题目链接: E-Easy Construction
题意:给出n, k, 求是否存在连续任意个数的和模n为k,并输出序列
Print n integers, the answer permutation in one line if such permutation exists, or print “-1” in one line if no solution exists.
2 1
1 2
详见注释
#include
using namespace std;
#pragma GCC optimize(2)
#define ios std::ios::sync_with_stdio(false);cin.tie(0), cout.tie(0);
#define rtxt freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
#define ll long long
const int Max = 1e6+3;
const int mod = 1e9+7;
int main()
{
ios
int n, k;
cin >> n >> k;
if(k != (n*(n+1)/2)%n) cout << -1 << endl;
else {
if(n&1) {
for(int i=1; i<=n/2; i++)
cout << i << " " << n-i << " ";
cout << n << endl;
}
else {
for(int i=1; i<n/2; i++)
cout << i << " " << n-i << " ";
cout << n/2 << " " << n << endl;
}
}
return 0;
}
蒟蒻一只,欢迎指正