codeforces 361B 思维题

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 ≤ 105, 0 ≤ 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.


codeforces上很多都是思维题,要敢于开脑洞。

假设b[I]为要输出的数组(从1到n编号)

拿这道题来说。首先我们能观察到几个性质:

1.b[1]无论是几,肯定是一个不好的数。

2题目要求m个好数,必然有n-m个坏数。除去b[1],还有n-m-1个坏数

3对任意b[k],只要k大于1,则若b[k]=k,它一定是一个好数。

4(很重要!)任意两个相邻的正整数,其最大公约数必然为1

5 因此,题目的坏数可以用性质4构造

至此,本题O(n)的解法已经出来了

b[1]=n-m,接下来的b[2]到b[n-m]不用我说了吧

剩下的b[k]=k


下面贴代码,没有用到数组

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<algorithm>
using namespace std;
#define zuida 100000
int n,m;

int main(void)
{

    scanf("%d%d",&n,&m);

    if(n==m)
        printf("-1");
    else
    {
        printf("%d ",n-m);
        for(int i=1;i<=n-m-1;i++)
        {
            printf("%d ",i);
        }
        for(int i=n-m+1;i<=n;i++)
            printf("%d ",i);
    }
    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值