题目链接:

A. 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 10^9.

Input
 

The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 10^5; 0 ≤ k ≤ 10^8).

Output
 

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

Examples
 
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.

题意

一个数列的数各不相同,每次取走前两个,得到gcd(x,y)的分数,问是否存在这样的长度为n,最后得分为k的数列;

思路

不存在的就不说了;

存在的时候可以第一次把k-n/2+1的分数得到,剩下的全都是gcd(x,y)==1的情况,需要用素数筛先处理出素数;

AC代码

#include <bits/stdc++.h>
using namespace std;
#define Riep(n) for(int i=1;i<=n;i++)
#define Riop(n) for(int i=0;i<n;i++)
#define Rjep(n) for(int j=1;j<=n;j++)
#define Rjop(n) for(int j=0;j<n;j++)
#define mst(ss,b) memset(ss,b,sizeof(ss));
typedef long long LL;
const LL mod=1e9+;
const double PI=acos(-1.0);
const int inf=0x3f3f3f3f;
const int N=1e6+5e5;
int a[N],flag[N];
int cnt=;
int getprime()
{ mst(flag,);
for(int i=;i<N;i++)
{
if(!flag[i])
{
a[cnt++]=i;
for(int j=;j*i<N;j++)
{
flag[i*j]=;
}
}
}
return cnt;
} int main()
{
int n,k;
scanf("%d%d",&n,&k);
getprime();
if(n==)
{
if(k==)cout<<""<<endl;
else cout<<"-1"<<endl;
}
else
{
if(n/>k)cout<<"-1"<<endl;
else
{
int m=k-n/+;
printf("%d %d ",m,*m);
int num=;
for(int i=;i<cnt&&num<n-;i++)
{
if(a[i]==m||a[i]==*m)continue;
else
{
printf("%d ",a[i]);
num++;
}
}
}
} return ;
}

最新文章

  1. 【转载】VGA时序与原理
  2. C语言中格式化输出的转换说明的fldwidth和precision解析
  3. Delphi在StatusBar上绘制ProgressBar
  4. vue-miniQQ——基于Vue2实现的仿手机QQ单页面应用(接入了聊天机器人,能够进行正常对话)
  5. 浅析Java中synchronized与static synchronized
  6. LOJ #2533. 「CTSC2018」暴力写挂(边分治合并)
  7. 第四次:渗透练习,xss学习
  8. week_one-python用户登录
  9. UDP广播包
  10. html常用标签整理
  11. explan各项说明
  12. 在Editplus直接运行程序的步骤
  13. Oracle 11G Client客户端安装
  14. 更新pip10后 ImportError: cannot import name ‘main&#39;
  15. Redis五大类型操作使用以及订阅发布功能
  16. 原生js(一)
  17. 兼容安卓和ios实现一键复制内容到剪切板
  18. UVa 10055
  19. 014 Java的反射机制
  20. Tomcat中部署Java Web应用程序的方式

热门文章

  1. Redis命令行之Zset
  2. android导入项目出错之解决办法
  3. android:logo
  4. 2017 ACM/ICPC Asia Regional Shenyang Online 记录
  5. 分布式架构和微服务CI/CD的范本技术解读
  6. Codeforces 616 E Sum of Remainders
  7. JDBC自定义连接池
  8. IOS -- base64编码
  9. J粒子发现40周年-丁肇中中科院讲座笔记
  10. awk批量处理文件,对第一列去重并,累加第二列数值,打印一二列存入新文件