程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> Codeforces Round #240 (Div. 2) Mashmokh and Numbers

Codeforces Round #240 (Div. 2) Mashmokh and Numbers

編輯:C++入門知識

題意找出一組數列,滿足每相鄰的兩個數的最大公因數和為給定的值。,注意相鄰兩個數的公約數為一就好做了,注意下邊界即可

C. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output

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 test(s) input
5 2
output
1 2 3 4 5
input
5 3
output
2 4 3 7 1
input
7 2
output
-1
Note

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

#include 
int main()
{
    int n,k;
    while(scanf("%d %d",&n,&k)==2)
    {
        if(n==1&&k!=0) printf("-1\n");
        else if(n==1&&k==0) printf("1\n");
        else if(n/2>k) printf("-1\n");
        else
        {
            int a=1,b=2;
            int t=n/2; t*=2; int x=n/2;
            int last=k-(x-1);
            for(int i=1;i


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved