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 ...
随机推荐
- Makefile 管理工具 — Automake and Autoconf
该project下载路径:http://files.cnblogs.com/iTsihang/hello-2.0.zip automake 參考资料:http://www.linuxforum.net ...
- Windows Phone开发(9):关于页面状态
原文:Windows Phone开发(9):关于页面状态 按照一般做法,刚学会如何导航,还是不够的,因为要知道,手机里面的每个页面,就如同Web页面一样,是无状态的. 啥是无状态?如果我们玩过Web开 ...
- hdu - 5045 - Contest(国家压缩dp)
意甲冠军:N个人M通过主打歌有自己的期望,每个问题发送人玩.它不能超过随机播放的次数1,追求最大业绩预期 (1 ≤ N ≤ 10,1 ≤ M ≤ 1000). 主题链接:pid=5045" ...
- HDU-3502-Huson's Adventure Island(BFS+如压力DP)
Problem Description A few days ago, Tom was tired of all the PC-games, so he went back to some old F ...
- Ubuntu下安装KDE及安装中文环境
进入Ubuntu的默认安装的桌面后打开终端,输入 sudo apt-get install kubuntu-desktop 回车后输入密码接下来提示下载KDE需要多少空间,解压后需要多少空间,询问是否 ...
- 实现能够直接粘QQ贴截图的bug管理功能
对于一个功能强大的协作平台来说,todo管理和bug管理是不可缺少的功能.Todo和bug往往不是通过一些简单的文字就能实现的,有时候须要配以图片的说名,之前用过的项目管理平台都是以附件的形式上传图片 ...
- 查看SQLSERVER内部数据页面的小插件Internals Viewer
原文:查看SQLSERVER内部数据页面的小插件Internals Viewer 查看SQLSERVER内部数据页面的小插件Internals Viewer 感觉internals viewer这个名 ...
- jdk阅读xml文件
前言 你需要阅读的时间来写一个通用组件xml文件,但考虑到组件分布更容易,这样一来在第三方小引用jar包.因此,直接jdk内建的xml分析方法.可能都没有第三发的组件强大. 导入的文件: import ...
- PHP情人:p十几天来学习hp第一天
我这里是暂时的 Apache web server 和 MY SQL 如WEB,在php-4.3.3下的环境做的程序.当然要简单的构建和訪问查看数据库 PHPMYADMIN 不可少. 以下简介一下P ...
- 用bat 删除当前文件夹下的某类文件
@echo on for /r %%f in (*.pdb,*.xml) do del %%f 保存为bat文件执行!