Codeforces 327B-Hungry Sequence(素数筛)
1 second
256 megabytes
standard input
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.
The input contains a single integer: n (1 ≤ n ≤ 105).
Output a line that contains n space-separated integers a1 a2,
..., 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.
3
2 9 15
5
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(素数筛)的更多相关文章
- CF 327B. Hungry Sequence
B. Hungry Sequence time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- 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 ...
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...
- codeforces 414A A. Mashmokh and Numbers(素数筛)
题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #511 (Div. 2)-C - Enlarge GCD (素数筛)
传送门:http://codeforces.com/contest/1047/problem/C 题意: 给定n个数,问最少要去掉几个数,使得剩下的数gcd 大于原来n个数的gcd值. 思路: 自己一 ...
- codeforces 822 D. My pretty girl Noora(dp+素数筛)
题目链接:http://codeforces.com/contest/822/problem/D 题解:做这题首先要推倒一下f(x)假设第各个阶段分成d1,d2,d3...di组取任意一组来说,如果第 ...
- Codeforces 385C - Bear and Prime Numbers(素数筛+前缀和+hashing)
385C - Bear and Prime Numbers 思路:记录数组中1-1e7中每个数出现的次数,然后用素数筛看哪些能被素数整除,并加到记录该素数的数组中,然后1-1e7求一遍前缀和. 代码: ...
- codeforces 569C C. Primes or Palindromes?(素数筛+dp)
题目链接: C. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes in ...
- Codeforces J. Soldier and Number Game(素数筛)
题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...
随机推荐
- Why 使用TLS记录封装IP层VPN IS A Bad Idea
一个很自然的想法,使用TLS套餐一IP数据报实现第三层VPN.这种想法必须经过深思熟虑的,但不幸的是,.这是一个错误的想法.有文章<Why TCP Over TCP Is A Bad Idea& ...
- Ubuntu Linux 永山(mount)分
在一般情况下,我们想安装一个分区解决方案是使用mount命令,因为我想/dev/sda3安装/media/aborn/data通过使用下面的命令 sudo mount /dev/sda3 /media ...
- 第一章_servlet
[Servlet与Jsp学习指南] *学习这servlet前.需要下载servlet-api.jar,MyEclipse给自己带来的需求javaEE3.0的天赋足以使用注解获得的版本号servlet ...
- tarjan算法(割点/割边/点连通分量/边连通分量/强连通分量)
tarjan算法是在dfs生成一颗dfs树的时候按照访问顺序的先后,为每个结点分配一个时间戳,然后再用low[u]表示结点能访问到的最小时间戳 以上的各种应用都是在此拓展而来的. 割点:如果一个图去掉 ...
- MySQL Windows ZIP 免费安装和启动设置
MySQL Windows ZIP免安装版,设置和启动的过程事实上挺麻烦的.以下一步一步介绍使用的过程: 1.下载Windows (x86, 64-bit), ZIP Archive: 2.解压zip ...
- 谈谈Linux内存释放
上上周吧,一个朋友问我说他公司的服务器内存free 为0 是为什么,意思大概是内存去哪了,这引发了一个小小的讨论,也就是内存释放的问题… 首先我们可能会用free 去查看内存的使用率,它应该是这样的 ...
- [WebView五学习]:调试Web Apps
上一篇我们学习了([WebView学习之四]:迁移到Android4.4版本号的WebView),今天我们来继续学习. (博客地址:http://blog.csdn.net/developer_jia ...
- BZOJ 3747 POI2015 Kinoman 段树
标题效果:有m点,每个点都有一个权值.现在我们有这个m为点的长度n该序列,寻求区间,它仅出现一次在正确的点区间内值和最大 想了很久,甚至神标题,奔说是水的问题--我醉了 枚举左点 对于每个请求留点右键 ...
- 【SICP读书笔记(一)】正则序展开的特殊情况
scheme解释器有两种实现方式,一种是应用序,先对每个参数求值,再以首过程对所有求得的参数求值. 第二种是正则序,会“完全展开然后归约”(书中原文) SICP中的练习1.5,让我困惑了一下.原题如下 ...
- OPhone SDK初体验
OPhone SDK初体验 write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie 讨论新闻组及文件 背景说明 中国伟大的垄断龙头,世界上也是顶尖的中移动最 ...