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. [C和指针] 1-快速上手、2-基本概念、3-数据

    第1章 快速上手 1.1.1 空白和注释   程序的空白的作用: 空行将程序的不同部分分割开来:制表符缩进语句,可以更好地显示程序的结构等等.     软件最大的开销并非在于编写,而是在于维护,所以需 ...

  2. Spring-security自定义配置器

    定义配置器 public final class MyFilterConfigurer<H extends HttpSecurityBuilder<H>> extends Se ...

  3. [转]MVC之 自定义过滤器(Filter)

    本文转自:http://www.cnblogs.com/kissdodog/archive/2013/01/21/2869298.html 一.自定义Filter 自定义Filter需要继承Actio ...

  4. NHibernate3.2学习笔记-几种查询方式

    一.开发环境 数据库:SQLServer2008 编译器:VS2010 .Net版本:.Net Framework 4.0 二.开发过程 1.项目结构 承接上一篇 2.执行sql语句 (1)基本语法 ...

  5. 计算给定数组 arr 中所有元素的总和的几种方法

    1.forEach遍历: function sum(arr) {     var result = 0;     arr.forEach(function(item,index) {          ...

  6. android中用Intent传数据,如果用传递的是一个类,就将类实现Parcelable接口

    Parcelable,内存单位,跨进程使用,或者intent传递对象的时候使用.android中用Intent传数据,如果用传递的是一个对象,就将对象实现Parcelable接口,而不是将对象序列化. ...

  7. 处理sql锁死问题

    --SQL Server死锁的查询方法:   exec master.dbo.p_lockinfo 0,0; ---显示死锁的进程,不显示正常的进程   exec master.dbo.p_locki ...

  8. C++_运算符重载 总结

    什么是运算符的重载? 运算符与类结合,产生新的含义. 为什么要引入运算符重载? 作用:为了实现类的多态性(多态是指一个函数名有多种含义) 怎么实现运算符的重载? 方式:类的成员函数 或 友元函数(类外 ...

  9. RESTful API设计的简单例子

    代码承接简单服务器,修改 app.js const koa = require('koa'), app = new koa(), Router = require('koa-router'), rou ...

  10. python安装外部模块Django

    Windows安装Django模块: 由于本人安装的Python版本是Python3.7,所以安装命令为:pip3 install django /pip3 install django安装过程中出现 ...