标签:std amp 欧拉筛法 include end mem iostream ems string
#include<iostream> #include<algorithm> #include<cstdio> #include<cstring> #define MAXN 100000 using namespace std; int pri[MAXN];///质数数列 bool vis[MAXN];///访问标志,也可记录最小素因子 int cnt = 0;///质数个数 void euler_sieve() { memset(pri, 0, sizeof(pri)); memset(vis, false, sizeof(vis)); //vis[0] = vis[1] = false; //pri[1] = pri[2] = 1; for(int i = 2; i < MAXN; i++) { if(!vis[i])pri[cnt++] = i; cout<<"prime"<<cnt<<":"<<pri[cnt-1]<<endl; for(int j = 0; j < cnt && i * pri[j] < MAXN; j++) { //ecout<<i*pri[j]<<endl; vis[i*pri[j]] = true; if(!(i%pri[j]))break; } } } int main() { int n; while(~scanf("%d", &n)) { euler_sieve(); for(int i = 0; i < cnt; i++)cout<<pri[i]<<endl; } return 0; }
标签:std amp 欧拉筛法 include end mem iostream ems string
原文地址:https://www.cnblogs.com/leftstan/p/13845119.html