Foreword
Erichsen sieve is a method of 2-n prime sieve, but the time complexity is not strong Euler screen, only O (n-* log log) but also a better understanding of the sieve
text
One, the prime basis Definitions
It refers to the prime natural numbers greater than 1, in addition to 1 and itself no other factors natural number. (Excerpt from Baidu Encyclopedia)
Second, the algorithm Detailed
All the 2-n number is marked as true, and then again scan cycle, respectively, each of the multiple number of marks to false (off screen), and so on.
Third, code implementation
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int maxn=1e6; 4 long long cc[maxn]; 5 bool vis[maxn]; 6 long long sum; 7 / * start screen prime function * / 8 void prime(int n) 9 { // sum statistics for the number of prime numbers; 10 sum = 0 11 memset (vis, true, sizeof vis); // array vis all the flag is true 12 for(int i=2;i<=n;++i) 13 { 14 if(vis[i]) 15 { 16 sum ++; // sum increases with the number of prime numbers increase 17 cc [sum] = i; // the prime number stored in the array cc 18 for(int j=2*i;j<=n;j+=i) 19 { 20 vis [j] = false; // the number is not a prime number flag to false 21 } 22 } 23 } 24 } 25 / * end function * / 26 int main () 27 { 28 int n; 29 cin>>n; 30 / * for n = 1 is judged Laid * / 31 if(n==1) 32 { 33 cout<<"Possible"<<endl; 34 } 35 / * end * special judge / 36 prime (n); 37 for(int i=1;i<=sum;++i) 38 { 39 cout << cc [i] << ""; // output to 40 } 41 return 0; 42 } 43