Mashmokh and Numbers

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 yfrom 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

题意:找出一组数列,满足每相邻的两个数的最大公因数和为给定的值。

sl:无以言状的水题,最终挂了,为什么呢,我把最后一个数字写的太小了。在知道直接0走起。

相邻两个数字互素。利用这点很容易求出答案。

1 #include<cstdio>

 2 #include<cstring>
 3 #include<algorithm>
 4 #include<queue>
 5 using namespace std;
 6 typedef long long LL;
 7 const int MAX = ;
 8 int main()
 9 {
     int n,k;
     while(scanf("%d %d",&n,&k)==)
     {
         if(n==&&k!=) printf("-1\n");
         else if(n==&&k==) printf("1\n");
         else if(n/>k) printf("-1\n");
         else
         {
             int a=,b=;
             int t=n/; t*=; int x=n/;
             int last=k-(x-);
             for(int i=;i<x;i++)
             {
                 if(a!=last&&b!=last&&a!=*last&&b!=*last)
                 {
                     if(i==) printf("%d %d",a,b),a+=, b+=;
                     else printf(" %d %d",a,b),a+=, b+=;
                 }
                 else
                 {
                     while(a==last||b==last||a==*last||b==*last)
                     a+=, b+=;
                     if(i==) printf("%d %d",a,b),a+=, b+=;
                     else printf(" %d %d",a,b),a+=, b+=;
 
                 }
             }
             if(x!=&&last!=) printf(" %d %d",*last,last);
             else if(last!=&&x==) printf("%d %d",*last,last);
             else if(x!=&&last==) printf(" 99999997 99999998");
             else if(last==&&x==) printf("99999997 99999998");
             if(n%) printf(" 1000000000");
             printf("\n");
         }
     }
     return ;
 }

Codeforces Round #240 (Div. 2) C Mashmokh and Numbers的更多相关文章

  1. Codeforces Round #240 (Div. 2)->A. Mashmokh and Lights

    A. Mashmokh and Lights time limit per test 1 second memory limit per test 256 megabytes input standa ...

  2. Codeforces Round #240 (Div. 1) B. Mashmokh and ACM DP

                                                 B. Mashmokh and ACM                                     ...

  3. Codeforces Round #240 (Div. 2)(A -- D)

    点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...

  4. Codeforces Round #240 (Div. 1)B---Mashmokh and ACM(水dp)

    Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university ...

  5. Codeforces Round #240 (Div. 2) B 好题

    B. Mashmokh and Tokens time limit per test 1 second memory limit per test 256 megabytes input standa ...

  6. Codeforces Round #240 (Div. 2) D

    , b2, ..., bl (1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n) is called good if each number divides (without a remainde ...

  7. Codeforces Round #240 (Div. 2) 题解

    A: 1分钟题,往后扫一遍 int a[MAXN]; int vis[MAXN]; int main(){ int n,m; cin>>n>>m; MEM(vis,); ; i ...

  8. Codeforces Round #235 (Div. 2) D. Roman and Numbers(如压力dp)

    Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standard i ...

  9. Codeforces Round #235 (Div. 2) D. Roman and Numbers 状压dp+数位dp

    题目链接: http://codeforces.com/problemset/problem/401/D D. Roman and Numbers time limit per test4 secon ...

随机推荐

  1. Spring boot 分环境部署

    一.如果配置文件为:application.properties时 1.application.properties用于填些公共文件 以下为不同环境的配置文件需要单独配置 application-de ...

  2. Android 性能优化(6)网络优化( 2) Analyzing Network Traffic Data:分析网络数据

    Analyzing Network Traffic Data 1.This lesson teaches you to Analyze App Network Traffic Analyze Netw ...

  3. ora-20000 unable to analyze

    ora-20000 unable to analyze 无法分析表 check: select * from wmsprdata.cmp3$88278表不存在. result:应该是系统自动任务2:0 ...

  4. 数据库恢复挂起解决办法【MSSQL】

    新建查询输入如下代码运行 - -把test改成你需要修复的数据库名 USE master GO ALTER DATABASE test SET SINGLE_USER GO ALTER DATABAS ...

  5. java死锁问题

    一.先从定义上了解一下死锁 二.从代码角度上去解释一下死锁问题 三.上述程序就是出现了死锁,我们来查看一下 1.命令如下   cmd>>jps(查看到了死锁线程所在的类,前面是PID) 2 ...

  6. PHP 在表单POST提交后数据分页实现,非GET,解决只有第一页显示正确的问题

    //PHP 在表单POST提交后数据分页实现,非GET,使用SESSION,分页代码部分不在详述,主要为POST后的 除第一页之外的显示问题 //以下为ACTION页面 内容,仅为事例,当判断到页面未 ...

  7. Tcl之Read files for synthesis

    The following file is to read all design files into syntehsis tool automatically, like Cadence RTL C ...

  8. STA之Concepts (2)

    3 Skew between signals Skew is the difference in timing between two or more signals, maybe data, clo ...

  9. 2-2 列表推导同 filter 和 map 的比较

    列表推导同 filter 和 map 的比较 参考廖雪峰的文档: filter()函数:用于过滤序列. filter()接收一个函数和一个序列.把传入的函数依次作用于传入的序列的每个元素,根据返回值是 ...

  10. 编写Java脚本统计工程代码总行数

    在新公司工作将近一年了,一直独自一人负责服务端集群的运维和代码的编写.不知不觉从一个Project发展到了七八个Project. 看着越来越多的代码,今天突然想统计一下一共写了多少代码.[这里只统计完 ...