Sieve of Eratosthenes

Category: Number Theory   Level: 101

cross out multiples of 2, 3, 5, 7 ⇒ 25 primes below 100

Circle the next number that is not crossed out, then cross out its multiples. Whatever survives is prime.

Step through it

Watch it

Animated walkthrough

Step by step

Step 1: Cross out 1

Write 1 to 100 in a grid. The number 1 is not prime, since a prime needs exactly two factors and 1 has only one.

1 is not prime

Step 1: Cross out 1

Step 2: Circle 2, cross out its multiples

Two is prime. Every other even number is a multiple of 2, so cross out 4, 6, 8, and so on. Half the grid goes in one move.

new crossings: 4, 6, 8, … (49 in all)

Step 2: Circle 2, cross out its multiples

Step 3: Circle 3, cross out its multiples

Three is the next survivor, so it is prime. Start crossing at 9, since 6 is already gone. Many multiples of 3 were crossed by 2 already.

new crossings: 9, 15, 21, … (16 in all)

Step 3: Circle 3, cross out its multiples

Step 4: Circle 5, cross out its multiples

Start at 25. Smaller multiples of 5, like 10, 15, and 20, already fell to 2 or 3.

new crossings: 25, 35, 55, … (6 in all)

Step 4: Circle 5, cross out its multiples

Step 5: Circle 7, cross out its multiples

Start at 49. Only three new numbers fall: 49, 77, and 91. The sieve is running out of work.

new crossings: 49, 77, 91 (3 in all)

Step 5: Circle 7, cross out its multiples

Step 6: Stop at the square root

The next prime is 11, but 11² = 121 is past 100. Any composite number up to 100 has a factor of 10 or less, so it is already crossed out. Every survivor is prime.

25 primes from 2 to 97

Step 6: Stop at the square root

All steps at once

Storyboard

Generate it yourself

cd svg-generator
python3 -m svgmath render sieve-of-eratosthenes --out /tmp/sieve-of-eratosthenes

Source: svgmath/diagrams/factors.py