题目链接:

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. Servlet 2.4 规范之第二篇:Servlet接口

    Servlet接口是Servlet API的最核心抽象类.所有的servlets都直接实现了这个接口,或者以更通用的方式继承了这个接口的实现类.Servlet API自带了两个实现了Servlet接口 ...

  2. 关于错误Access Violation和too many consecutive exceptions 解决方法

    关于错误Access Violation和too many consecutive exceptions 解决方法 “如果DLL中用到了DELPHI的string类型,则DLL和主程序中都需要加上Sh ...

  3. Jmeter中处理json

    我们在做http接口测试的时候,返回的数据都是json串,Jmeter中本身是不支持直接处理json串的,如果要获取到返回结果中指定的值,必须要要通过正则表达式来获取到,正则表达式比较麻烦,写错了就获 ...

  4. 王垠:谈 Linux,Windows 和 Mac ( 2013)

    这段时间受到很多人的来信.他们看了我很早以前写的推崇 Linux 的文章,想知道如何“抛弃 Windows,学习 Linux”.天知道他们在哪里找到那么老的文章,真是好事不出门…… 我觉得我有责任消除 ...

  5. delphi 与 sqlite3

      delphi与sqlite file:0 前言 本文的目的在于采用流水账方式来记录学习delphi访问嵌入式数据库sqlite中的一些点滴.欢迎各位同好共同学习和批评指正. file:1 准备工作 ...

  6. AtoS查看iOS Crash log中的16进制代码日志

    注意:crash_log一定要和打包时的archive对应上: 方法1)在Orgnizer里找到某一个archive,即:/Users/handywang/Library/Developer/Xcod ...

  7. [React] Create and import React components with Markdown using MDXC

    In this lesson I demonstrate how to use the library MDXC to create and import React components with ...

  8. cocos2d-x wp8 中文显示问题

    cocos2d-x项目在wp8下中文显示不了.有两个原因: 1. 本身字符串的utf8编码, 有问题. 2. 显示中文所须要的字体,缺失. 要解决第二个问题非常easy,在fonts下加入一个中文字体 ...

  9. jquery 常用选择器 回顾 ajax() parent() parents() children() siblings() find() eq() has() filter() next()

    1. $.ajax() ajax 本身是异步操作,当需要将 异步 改为 同步时: async: false 2.parent()  父级元素  和  parents() 祖先元素 的区别 parent ...

  10. 【leetcode】 26. Remove Duplicates from Sorted Array

    @requires_authorization @author johnsondu @create_time 2015.7.22 18:58 @url [remove dublicates from ...