Codeforce Round #210 Div2 B
Levko loves permutations very much. A permutation of length n is a sequence of distinct positive integers, each is at most n.
Let’s assume that value gcd(a, b) shows the greatest common divisor of numbers a and b. Levko assumes that element pi of permutation p1, p2, ... , pn is good if gcd(i, pi) > 1. Levko considers a permutation beautiful, if it has exactly k good elements. Unfortunately, he doesn’t know any beautiful permutation. Your task is to help him to find at least one of them.
The single line contains two integers n and k (1 ≤ n ≤ 105, 0 ≤ k ≤ n).
In a single line print either any beautiful permutation or -1, if such permutation doesn’t exist.
If there are multiple suitable permutations, you are allowed to print any of them.
4 2
2 4 3 1
1 1
-1
In the first sample elements 4 and 3 are good because gcd(2, 4) = 2 > 1 and gcd(3, 3) = 3 > 1. Elements 2 and 1 are not good because gcd(1, 2) = 1 and gcd(4, 1) = 1. As there are exactly 2 good elements, the permutation is beautiful.
The second sample has no beautiful permutations.
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include <map> 3 #include <stack> 4 #include <queue> 5 #include <vector> 6 #include <string> 7 #include <cmath> 8 #include <cstdio> 9 #include <cstring> 10 #include <cstdlib> 11 #include <iostream> 12 #include <algorithm> 13 using namespace std; 14 #define maxn 10055 15 #define ll long long 16 #define mod 1000000007 17 #define INF 0x7fffffff 18 #define eps 1e-8 19 int n, m, k, sx, sy; 20 int a[maxn]; 21 int main(){ 22 int t; 23 //scanf("%d", &t); 24 //while (t--){ 25 //memset(a, 0, sizeof a); 26 //memset(b, 0, sizeof b); 27 scanf("%d%d", &n, &m); 28 if (m == n){ printf("-1\n"); return 0; } 29 for (int i = 1; i <= n; i++){ 30 if (i < n - m)printf("%d ", i + 1); 31 if (i == n - m)printf("1 "); 32 if (i>n - m)printf("%d ", i); 33 } 34 printf("\n"); 35 //} 36 return 0; 37 }
浙公网安备 33010602011771号