Today, a faster sieve has been found, a whole lot faster than the previous one, although most of the topics will not be as stringent as time requirements, but a faster algorithm will be great.
Previous use of the vegetarian sieve:
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<queue>using namespacestd;Const intMaxn= (1<< -)+1;BOOLisprime[maxn+5];intprime[maxn+5],cnt=0;void Get(){ for(intI=2; i<=maxn;i++) { if(!Isprime[i]) {prime[cnt++]=i; for(intj=i+i;j<=maxn;j+=i) isprime[j]=1; } }}intMain () {Get(); cout<<cnt<<Endl; printf ("%d%d%d\n", prime[0],prime[1],prime[2]); return 0;}
Faster vegetarian sieves:
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>#include<queue>using namespacestd;Const intMaxn= (1<< -)+1;BOOLisprime[maxn+5];intprime[maxn+5],cnt=0;void Get(){ for(intI=2; i<=maxn;i++) { if(!Isprime[i]) prime[cnt++]=i; for(intj=0; j<cnt&&i*prime[j]<=maxn;j++) {Isprime[i*prime[j]]=1; if(i%prime[j]==0) Break;//Notice the order of the two sentences } }}intMain () {Get(); cout<<cnt<<Endl; printf ("%d%d%d\n", prime[0],prime[1],prime[2]); return 0;}
Prime number Screening Method