Numbers wing · about 2,200 years old

The Sieve of Eratosthenes

How do you find every prime number up to 100, without testing each one by dividing? You don't look for primes at all. You throw away everything that isn't prime, and what's left over is the primes.

Words to know
The recipe
  1. Cross out 1. It isn't prime.
  2. Find the smallest number that isn't marked yet. Circle it: nothing smaller than it divides it, so it's prime.
  3. Cross out all of its multiples. Each one has a divisor besides 1 and itself, so none of them can be prime.
  4. Go back to step 2 until every number is circled or crossed out.

Click 1 to start.

Primes found: 0 Crossings out: 0 Wasted crossings (already crossed out): 0
circled: prime crossed out: not prime
Detective questions
  1. When you clicked 11 on the 1-to-100 board, nothing new was crossed out: 22, 33, 44 … 99 were already gone. Why? (Hint: 22 = 11 × 2. Which smaller prime crossed it out?)
  2. What is the first multiple of 11 that no smaller prime would cross out? So after which prime could you have stopped, and known that every number left is prime?
  3. Turn on the shortcut and sieve again. How many wasted crossings do you save? Why is it safe to start at p × p?
  4. Switch to Ulam's spiral and finish the sieve. Do the primes look random, or do you see lines?
Curator's answers
  1. Every multiple of 11 below 121 is 11 × something smaller than 11, like 11 × 2 or 11 × 9. That smaller number has a prime divisor smaller than 11, and that prime already crossed it out.
  2. 11 × 11 = 121. On a board up to 100, nothing new gets crossed out after 7, because 11 × 11 is past 100. In general you can stop at the largest prime whose square is still on the board: for a board up to N, you only need primes up to the square root of N.
  3. For the same reason: every multiple of p smaller than p × p is p × (something smaller than p), and a smaller prime has already crossed it out.
  4. Lines! Many primes line up along diagonals. Stanisław Ulam noticed this in 1963. As he told the story, he was doodling during a boring talk at a meeting. Mathematicians can explain some of the lines but still can't fully predict them.

Why it's clever

Testing whether one number is prime means trying lots of divisions. The sieve never divides at all: it only counts forward by steps (2, 4, 6, 8 …, then 3, 6, 9 …). Each crossed-out number gets crossed out by its smallest prime first. That's why the sieve is still one of the fastest ways to list all the primes up to a few billion.

The primes it finds are the raw material for RSA, the lock-and-key math that protects messages on the internet. RSA starts by picking two primes.

From the archive

Eratosthenes (about 276–194 BC) was born in Cyrene, in today's Libya, and ran the great Library of Alexandria in Egypt. He also worked out the size of the Earth from the length of shadows, and by most estimates came remarkably close. None of his own books about the sieve survive. We know the method from Introduction to Arithmetic, written about 300 years later by Nicomachus of Gerasa, who credits it to him.