?Download sourceCode.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | //0maxmprime12forj+iprime0 #include<iostream> #include<cmath> #include<cstdio> using namespace std; int const maxm=1000001; int prime[maxm]; void sievePrime() { for(int i=0;i<maxm;i++) prime[i]=1; prime[0]=0; prime[1]=0; int max=sqrt(maxm*1.0); for(int i=2;i<=max;i++) { if(prime[i]) for(int j=i+i;j<maxm;j=j+i) { prime[j]=0; } } } int main() { sievePrime(); int i; for(i=0;i<100;i++){ if(prime[i]) printf("\n%d\n",i); } return 0; } |
code
more code
~~~~