标签:nyoj 快速查找素数
5 10 11 0
2 3 5 2 3 5 7 2 3 5 7 11
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define max 2000005
using namespace std;
int isprime[max];
void count(){
int i,j;
for(i=2;i*i<max;++i){
if(isprime[i])continue;
for(j=i*i;j<max;j+=i)
isprime[j]=1;
}
}
int main()
{
count();
int i,j,n;
while(scanf("%d",&n),n){
for(i=2;i<=n;++i)
if(!isprime[i])
printf("%d ",i);
printf("\n");
}
return 0;
}
标签:nyoj 快速查找素数
原文地址:http://blog.csdn.net/r1986799047/article/details/42780189