CodeForces 414A Mashmokh and Numbers(模拟)

来源:互联网 发布:l300清零软件 编辑:程序博客网 时间:2024/06/12 00:49
C - Mashmokh and Numbers
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u
Description

It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.

In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and y from the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.

Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.

Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.

Input

The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).

Output

If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).

Sample Input

Input
5 2
Output
1 2 3 4 5
Input
5 3
Output
2 4 3 7 1
Input
7 2
Output
-1

Hint

gcd(x, y) is greatest common divisor of x and y.

题目大意:给出两个整数n和k,找出n个不同的数。如果n为偶数,gcd(a1,a2)+gcd(a3,a4)+……+gcd(an-1,an)=k;如果n为奇数,gcd(a1,a2)+gcd(a3,a4)+……+gcd(an-2,an-1)=k。
比赛的时候一直在看其他的题,没看这道题,其实这题也很简单的。
分析:因为每两个数得出一个数,设a=n/2,
如果a>k,即每两个数的最大公约数都为1时都不能满足题意,输出-1;如果k=0,且n>=2时,同样输出-1。
如果a=k,那么只要使每一组的最大公约数为1即可。
如果a<k,令a-1组的最大公约数为1,第一组的最大公约数为k-a+1即可。
#include<stdio.h>int main(){    int n, k, i, j;    while(~scanf("%d%d",&n,&k))    {        int a = n / 2;        if(a > k || (a == 0 && k != 0))            printf("-1\n");        else if(a == k)        {            for(i = 1; i <= n; i++)            {                if(i > 1) printf(" ");                printf("%d", i);            }            printf("\n");        }        else        {            int tmp = k - a + 1;            printf("%d %d", tmp, tmp*2);            for(i = tmp * 2 + 1, j = 1; j < a; i += 2, j++)                printf(" %d %d",i, i+1);            if(n % 2 == 1)                printf(" %d", i);            printf("\n");        }    }    return 0;}



0 0