Current location - Training Enrollment Network - Mathematics courses - What is the principle of Euler sieve? (algorithm)
What is the principle of Euler sieve? (algorithm)
Principle: multiples of prime numbers must not be prime numbers.

We can store information with an array of length n+ 1 (this method of storing information with another array is very common and useful). First, all numbers are initialized to 0 (prime number), and then the number 1 and the first prime number 2 are marked as 1 (non-prime number). Starting with prime number 2, all multiples of 2 less than n are marked as 65438. Continue this process, filter out multiples of prime number 3, and the cycle ends. The number marked with 0 is the prime number.