标签:
#include <cstdio> #include <cstring> #include <iostream> #include <cmath> #include<vector> #include<algorithm> using namespace std; typedef long long LL; const int maxn=1000007; const int INF=0x3f3f3f3f; const int mod=1000003; LL a[maxn], vis[maxn], k; ///素数打表数组a里面存的就是2到MAXN之间的素数 void IsPrime() { k=0; for(int i=2; i<maxn; i++) { ///用数组vis做标记数组 if(!vis[i])///数组在没有初始化时,默认为都为0,不用初始化数组的原因 { a[k++]=i; ///i倍数不会是素数标记为1 for(int j=i+i; j<maxn; j+=i) vis[j]=1; } } } ///主函数把素数输出看的更明显 int main() { IsPrime(); int n; while(~scanf("%d", &n)) { for(int i=0; i<n; i++) printf("%lld ", a[i]); printf("\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/w-y-1/p/5760136.html