Erichsen core screening method is: a multiple of prime numbers is not a prime number.
Then we implement such a strategy, we can determine that 2 is the smallest prime number, create a table and the addition of 01 all numbers marked as a prime number, we will be screening factor in the range of 2 all marked as number (non-alloy prime number), and then remove the smallest prime number table, the same strategy (speaking prime multiples marked as non-prime). The chart below demonstrates such a perfect algorithm
The complexity of the screen Erichsen only O (nloglogn), regarded as relatively fast. When the amount of data is not too large, it can be seen as complexity is linear.
const int max_num = 10000 + 10; bool is_prime[max_num]; void prime_table(int maxn) { memset(is_prime, 1, sizeof(is_prime)); is_prime[0] = is_prime[1] = false; for(int i = 2; i <= maxn; i++) { if(is_prime[i]) { for(int j = 2 * i; j <= maxn; j += i) is_prime[j] = false; } } }