题目链接:

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. 结构字段验证--validator.v9

    官网:https://godoc.org/gopkg.in/go-playground/validator.v9#hdr-Baked_In_Validators_and_Tags package va ...

  2. Mysql Binlog日志文件介绍

    一.Binlog简介 官方文档参考 https://dev.mysql.com/doc/refman/5.5/en/binary-log.html Binlog(Binary Log) 指数据库的表创 ...

  3. css3 改变默认选中文本背景色和文本颜色

    ::selection { background:#d3d3d3; color:#555; } ::-moz-selection { background:#d3d3d3; color:#555; } ...

  4. MySQL与MSSQL的一些语法差异(持续更新中)

    分号不能少:分号不能少:分号不能少:重要的事情说3遍 Insert或者Update的数据包含反斜杠\的时候需要进行转义\\,例:insert into tablename(id,name) value ...

  5. Netty入门教程:Netty拆包粘包技术讲解

    Netty编解码技术是什么意思呢?所谓的编解码技术,说白了就是java序列化技术.序列化有两个目的: 1.进行网络传输2.对象持久化 虽然我们可以使用java进行序列化,Netty去传输.但是java ...

  6. java集合系列之HashMap源码

    java集合系列之HashMap源码 HashMap的源码可真不好消化!!! 首先简单介绍一下HashMap集合的特点.HashMap存放键值对,键值对封装在Node(代码如下,比较简单,不再介绍)节 ...

  7. (type interface {}) to type string

    go 语言开发中,经常会在函数中碰到使用 insterface{} 作为接收任意参数,但是我们接收的数据经常是需要做类型转换,由于是初学者,因此,初次转换我是直接就 func New(paramete ...

  8. NHibernate之旅(7):初探NHibernate中的并发控制

    本节内容 什么是并发控制? 悲观并发控制(Pessimistic Concurrency) 乐观并发控制(Optimistic Concurrency) NHibernate支持乐观并发控制 实例分析 ...

  9. POJ3420 Quad Tiling DP + 矩阵高速幂

    题目大意是用1*2的骨牌堆积成4*N的矩形.一共同拥有多少种方法,N不超过10^9. 这题和以前在庞果网上做过的一道木块砌墙差点儿一样. 由于骨牌我们能够横着放.竖着放.我们如果以4为列,N为行这样去 ...

  10. (转) Universal-Image-Loader使用大全(史上最屌)

    转载自http://blog.csdn.net/zenjj11/article/details/38728481 项目介绍: Android上最让人头疼的莫过于从网络获取图片.显示.回收,不论什么一个 ...