题目描述
Roundgod is given n, k, construct a permutation of
satisfying that for all integers
in
, there exists a contiguous subarray in
of length
whose sum is kk modulo nn. If there are multiple solutions, print any of them. If there is no solution, print "-1" in one line.
输入描述
The first line contains two integers ,
.
输出描述
Print integers, the answer permutation in one line if such permutation exists, or print "-1" in one line if no solution exists.
示例1
输入
2 1
输出
1 2
说明
The sum of subintervals both satisfy
, and their lengths are
respectively.
示例2
输入
3 1
输出
-1
分析
,
存在子列满足,子列各个元素的和与
模
同余;当
时,子列的和为
,故
。
当 为奇数,若
,则有解;令
即可。
当 为偶数,若
,则有解;令
即可。
代码
/****************************************************************** Copyright: 11D_Beyonder All Rights Reserved Author: 11D_Beyonder Problem ID: 2020牛客暑期多校训练营(第五场) Problem E Date: 8/24/2020 Description: Construction *******************************************************************/ #include<iostream> #include<cstdio> using namespace std; int main(){ int n,k; cin>>n>>k; if(n&1){ if(!k){ cout<<n; for(register int i=1;i<=n/2;i++){ printf(" %d %d",i,n-i); } putchar('\n'); }else{ puts("-1"); } }else{ if(k==n/2){ cout<<n<<' '<<n/2; for(register int i=1;i<n/2;i++){ printf(" %d %d",i,n-i); } putchar('\n'); }else{ puts("-1"); } } return 0; }