In fact, anyone can judge prime numbers, so this article skips the simple prime number judgment, and directly learns how to quickly judge the prime numbers from 1 to N, and judge whether the big data is a prime number.
Now let's learn the Ehrlich screening method. This method is practical and large-scale to determine prime numbers, such as those from 1 to N, and so on.
This algorithm is cheating, and it's as old as the tossing and turning method.
First, write down all integers in the range 2 to n. The smallest number 2 is a prime number, so cross out the multiples of 2 in the table. The smallest number remaining in the table is 3, which is not divisible by smaller numbers and is a prime number. If the smallest in the table is m, and m is a prime number, cross out the multiples of m.
2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
2 | 3 | - | 5 | - | 7 | - | 9 | - | 11 | - |
2 | 3 | - | 5 | - | 7 | - | - | - | 11 | - |