B. Hungry Sequence
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Iahub and Iahubina went to a date at a luxury restaurant. Everything went fine until paying for the food. Instead of money, the waiter wants Iahub to write a Hungry sequence consisting of n integers.

A sequence a1, a2,
..., an, consisting
of n integers, is Hungry if and only if:

  • Its elements are in increasing order. That is an inequality ai < aj holds
    for any two indices i, j (i < j).
  • For any two indices i and j (i < j), aj must not be
    divisible by ai.

Iahub is in trouble, so he asks you for help. Find a Hungry sequence with n elements.

Input

The input contains a single integer: n (1 ≤ n ≤ 105).

Output

Output a line that contains n space-separated integers aa2,
..., an (1 ≤ ai ≤ 107),
representing a possible Hungry sequence. Note, that each ai must
not be greater than 10000000 (107)
and less than 1.

If there are multiple solutions you can output any one.

Sample test(s)
input
3
output
2 9 15
input
5
output
11 14 20 27 31
题意:要求生成一个含n个数的数列,对于数列要求:1.升序。2.数列中的随意两个数互质。
这尼玛就是要输出素数嘛。

。
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cstdlib>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;
const int INF=0x3f3f3f3f;
#define LL long long
int prime[10000010],vis[10000010],num;
void init()
{
memset(vis,1,sizeof(vis));
num=0;
for(int i=2;i<10000000;i++)
{
if(vis[i])
{
prime[num++]=i;
for(int j=2;j*i<10000000;j++)
vis[j*i]=0;
}
}
}
int main()
{
init();
int n;
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
if(i!=n-1)
printf("%d ",prime[i]);
else
printf("%d\n",prime[i]);
}
return 0;
}

版权声明:本文博客原创文章。博客,未经同意,不得转载。

Codeforces 327B-Hungry Sequence(素数筛)的更多相关文章

  1. CF 327B. Hungry Sequence

    B. Hungry Sequence time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. Codeforces Round #191 (Div. 2) B. Hungry Sequence(素数筛选法)

    . Hungry Sequence time limit per test 1 second memory limit per test 256 megabytes input standard in ...

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

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

  4. codeforces 414A A. Mashmokh and Numbers(素数筛)

    题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input ...

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

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

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

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

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

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

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

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

  9. Codeforces J. Soldier and Number Game(素数筛)

    题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

随机推荐

  1. Git管理工具对照(GitBash、EGit、SourceTree)

    Git管理工具对照(GitBash.EGit.SourceTree) GitBash是採用命令行的方式对版本号进行管理,功能最为灵活强大,可是由于须要手动输入希望改动的文件名称,所以相对繁琐. EGi ...

  2. 《JavaScript设计模式与开发实践》读书笔记之观察者模式

    1.观察者模式 观察者模式定义对象间的一种一对多的依赖关系,当一个对象的状态发生改变时,所有依赖于它的对象都将得到通知. JavaScript中通常采用事件模型替代传统的观察者模式 1.1 逐步实现观 ...

  3. Java命令参数说明

    Java在运行已编译完成的类时,是通过java虚拟机来装载和执行的,java虚拟机通过操作系统命令 JAVA_HOME"bin"java –option 来启动,-option为虚 ...

  4. 两个实验操作系统-ubuntu在安装配置pintos

    安前两次莫名其妙, 蛋疼的实验操作系统.. 首先下错了总结第一次. 使用最后gdb调试pintos什么时候, 这个错误将被报告: bochsrc.txt:8: Bochs is not compile ...

  5. uvalive4015 (树上背包)

    给一棵树,边上有权值,然后给一个权值x,问从根结点出发, 走不超过x的距离,最多能经过多少个结点. 走过的点可以重复走,所以可以从一个分支走下去,然后走回来,然后再走另一个分支 dp[u][j][0] ...

  6. poj 3101 Astronomy(分数的最小公倍数)

    http://poj.org/problem? id=3101 大致题意:求n个运动周期不全然同样的天体在一条直线上的周期. 这题我是看解题报告写的,没想到选用參照物,用到了物理中的角速度什么的. 由 ...

  7. IOS开发-通知与消息机制

    在多数移动应用中不论什么时候都仅仅能有一个应用程序处于活跃状态.假设其它应用此刻发生了一些用户感兴趣的那么通过通知机制就能够告诉用户此时发生的事情. iOS中通知机制又叫消息机制,其包含两类:一类是本 ...

  8. J2SE基础:4.面向对象的特性一

    面向对象的特性 封装 继承多态 封装: 定义: 通过对象的封装,实现了模块化和信息隐藏. 通过对类的成员施以一定的訪问权限,实现了类中成员 的信息隐藏 注意点: 对象自已该做的一些事情与方法不能交与其 ...

  9. IOS加强知识(1)理解力Objective-C

    一直想写一般Objective-C帖子,总是没时间.所以,我希望有一个巨大的知识更小.温馨提示小的变化.写一点点,每天.东西把他们的学习分享,好了废话不多. 1.一门动态的语言OC Object-C( ...

  10. 小米2S Mk6.0.1 [只能做测试体验,不能使用]

    上几张高清图片.. 说明: 此版本只能做测试体验,不能做实际使用. 开发者: laser杨万荣 感谢: 秋叶随风ivan, m1cha 及 MoKee Open Source的各位开发者 下载地址:链 ...