CodeForces

来源:互联网 发布:增加淘宝店铺流量 编辑:程序博客网 时间:2024/06/05 09:33

B. Levko and Permutation
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Input

The single line contains two integers n and k (1 ≤ n ≤ 1050 ≤ k ≤ n).

Output

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.

Examples
input
4 2
output
2 4 3 1
input
1 1
output
-1
Note

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.


题意:给定n和k,找到一个长度为n的序列,里面的数是1~n且洽有k个数和1的gcd大于1,其余n-k个数和1的gcd均等于1。


思路:1和任何数的gcd都等于1,除1外任何数和它自己的gcd都大于1,和它下一个数的gcd都等于1。

不可能所有的数的gcd都大于1(因为有1)。

下边 2~k+1 为数本身(gcd大于1)

k+2~n 为下标加一,即k+3~n+1%n=1(gcd等于1)

1 为k+2

#include <iostream>#include <cstdio>#include <algorithm>#define max_ 3010using namespace std;int n,k;int main(){cin>>n>>k;if(n==k){printf("-1\n");return 0;}for(int i=1;i<=n;i++){if(i==1)printf("%d",(k+2-1)%n+1);else if(i-1<=k)printf(" %d",i);elseprintf(" %d",(i+1-1)%n+1);}printf("\n");}


原创粉丝点击