How does one list all the prime numbers up to a given number ? Eratosthenes of Cyrene (3rd century BC, librarian of Alexandria) invented an elegant algorithm: the sieve (in Greek koskinon, “sieve”), which is still today the simplest method for generating tables of prime numbers.
Example — Sieve of Eratosthenes up to 30
One writes the numbers from to and proceeds as follows:
- Circle the first uncrossed number (): it is prime.
- Cross out all its subsequent multiples ().
- Go back to step 1 on the next uncrossed number (), then , then .
- When you reach a prime with (here , since ) you may stop: all the remaining uncrossed numbers are prime.
There remain: — the primes up to .
The sieve up to 30: circled in red the primes, in grey the numbers crossed out because composite.
Links
Topics: Numbers and operations
Concepts: Sieve of Eratosthenes · Prime number
Methods: Sieve of Eratosthenes
Skills: Calculate
People: Eratosthenes