题目链接:

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 ;
}

codeforces 414A A. Mashmokh and Numbers(素数筛)的更多相关文章

  1. codeforces 569C C. Primes or Palindromes?(素数筛+dp)

    题目链接: C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes in ...

  2. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  3. CodeForces 385C Bear and Prime Numbers 素数打表

    第一眼看这道题目的时候觉得可能会很难也看不太懂,但是看了给出的Hint之后思路就十分清晰了 Consider the first sample. Overall, the first sample h ...

  4. Codeforces 385C - Bear and Prime Numbers(素数筛+前缀和+hashing)

    385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: ...

  5. Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

  6. Codeforces Round #511 (Div. 2)-C - Enlarge GCD (素数筛)

    传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一 ...

  7. codeforces 822 D. My pretty girl Noora(dp+素数筛)

    题目链接:http://codeforces.com/contest/822/problem/D 题解:做这题首先要推倒一下f(x)假设第各个阶段分成d1,d2,d3...di组取任意一组来说,如果第 ...

  8. UVALive-3399-Sum of Consecutive Prime Numbers(素数筛,暴力)

    原题链接 写个素数筛暴力打表一波就AC了: #include <iostream> using namespace std; const int N = 10001; int i, j, ...

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

    , a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge ...

随机推荐

  1. Jsp中路径问题

    ${pageContext.request.contextPath}”的作用是取出部署的应用程序名,这样不管如何部署,所用路径都是正确的. <!--使用绝对路径的方式引入CSS文件-->& ...

  2. 数据库数据导出CSV文件,浏览器下载

    直接上代码: def download(request): # 从数据库查询数据 data_list = Info.objects.all() # 定义返回对象 response = HttpResp ...

  3. elasticsearch入门使用(三) Query DSL

    Elasticsearch Reference [6.2] » Query DSL 参考官方文档 :https://www.elastic.co/guide/en/elasticsearch/refe ...

  4. 关于整合spring+mybatis 第二种方式

    和第一种方式一样的步骤,不过bean.xml中有些许差异 <!-- 配置sqlSessionFactory --> <bean id="sqlSessionFactory& ...

  5. .net core webapi jwt 更为清爽的认证 ,续期很简单

    我的方式非主流,控制却可以更加灵活,喜欢的朋友,不妨花一点时间学习一下 jwt认证分为两部分,第一部分是加密解密,第二部分是灵活的应用于中间件,我的处理方式是将获取token放到api的一个具体的co ...

  6. 树莓派学习笔记——I2C设备载入和速率设置

    原文:http://blog.csdn.net/xukai871105/article/details/18234075 1.载入设备 方法1——临时载入设备 sudo modprobe -r i2c ...

  7. 基于SSH+shiro+solr的家庭记账系统

    项目地址: https://github.com/jianghuxiaoao/homeaccount

  8. [AngularJS Unit tesint] Testing keyboard event

    HTML: <div ng-focus="vm.onFocus(month)", aria-focus="{{vm.focus == month}}", ...

  9. 搭建企业内部DNS服务器,docker 部署内部 dnsmasq

    获取镜像 docker pull jpillora/dnsmasq 配置域名 # http://oss.segetech.com/intra/srv/dnsmasq.conf #log all dns ...

  10. 一个能自己主动搜索源文件并自己主动推导的Makefile

    今天看了一天的makefile的写法.东拼西凑.好不easy写出了一个makefile.颇有成就感,记录下来,以备温习之用. 如果有两个头文件文件夹 header1,header2;两个cpp文件文件 ...