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

 

posted @ 2014-04-17 16:45  null1019  阅读(135)  评论(0编辑  收藏  举报