cf B. Hungry Sequence

http://codeforces.com/contest/327/problem/B

这道题素数打表就行。

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <iostream>
 4 #include <algorithm>
 5 #define maxn 2000100
 6 using namespace std;
 7 
 8 bool f[maxn];
 9 int a[maxn];
10 int t;
11 
12 void prime()
13 {
14     memset(f,false,sizeof(f));
15     f[0]=true; f[1]=true;;
16     for(int i=2; i*i<maxn; i++)
17     {
18         if(!f[i])
19         {
20             for(int j=i+i; j<=maxn; j+=i)
21             {
22                 f[j]=true;
23             }
24         }
25     }
26     t=0;
27     for(int i=0; i<maxn; i++)
28     {
29         if(!f[i]) a[t++]=i;
30     }
31 }
32 
33 int main()
34 {
35     int n;
36     prime();
37     scanf("%d",&n);
38     for(int i=0; i<n; i++)
39     {
40         if(i==0) printf("%d",a[i]);
41         else printf(" %d",a[i]);
42     }
43     printf("\n");
44     return 0;
45 }
View Code

 

转载于:https://www.cnblogs.com/fanminghui/p/3671131.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值