[ICPC2020南京K] K Co-prime Permutation - 构造
作者:互联网
[ICPC2020南京K] K Co-prime Permutation - 构造
Description
给定n,k,要求构造一个排列a,满足存在恰好k对:\(gcd(a[i],i)=1\),如果无解输出-1.
Solution
由于 \(gcd(x-1,x)=1\),将前 \(k\) 个数循环移位即可
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n, k, a[1000005];
signed main()
{
ios::sync_with_stdio(false);
cin >> n >> k;
iota(a + 1, a + n + 1, 1);
if (k == 0)
{
cout << -1 << endl;
}
else
{
rotate(a + 1, a + 2, a + k + 1);
for (int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
}
}
标签:prime,ICPC2020,Co,gcd,int,long,Permutation 来源: https://www.cnblogs.com/mollnn/p/14587979.html