Why it happens

Why the Primes Never Run Out

Multiply any list of primes and add 1. Every listed prime leaves remainder 1 when it divides the result, so the primes that do divide it are missing from the list. No finite list holds them all. For the first six primes the number is 30,031, which isn't prime: it's 59 × 509, two primes the list missed.

The Sieve of Eratosthenes, 1 to 400

StopSieve of Eratosthenes
Numbers up to
Sieving with–Crossed out0Primes found0n / ln n66.8

The numbers 1 to 400

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400

Green: prime. Gray: crossed out. Red: crossed out on this step.

Primes counted against n / ln n

020406080050100150200250300350400nprimes up to n

Primes up to n, divided by n / ln n

1/22Write the numbers 1 to 400 in a grid. 1 is neither prime nor composite. Every other number is either prime or a product of smaller primes, and the sieve will cross out the products.

  • CH1 known so far
  • CH2 n / ln n

Watch the Python behind this model run, line by line

How to read the stage

Objective
Read the grid and the chart, and say why the sieve can stop once the next prime's square passes 400.
How this step gets you there
The text walks the first and last steps of the default run and names what each panel counts.

The grid holds 1 to 400. Each step takes the next number still standing, marks it prime, and crosses out its multiples from its square up, the new ones in red. 2 alone crosses out 199. After 19, the next prime is 23, and 23 × 23 = 529 is past 400, so the 78 numbers still standing are all prime. The chart counts them against n / ln n.

Euclid's proof, run on a list

Objective
Explain why the product of a list of primes, plus 1, always has a prime factor that isn't on the list.
How this step gets you there
The stage builds the number from a list you pick, divides it by each listed prime, then factors it.

Euclid's Elements, Book IX, Proposition 20, says that prime numbers are more than any assigned multitude of prime numbers. Take the first six primes: their product is 30,030, so 30,031 leaves remainder 1 when divided by each of them. A listed prime that divided 30,031 would also divide that 1. So every prime that divides 30,031 is new, here 59 and 509. Any list works the same way.

Euclid's proof on the first six primes

StopEuclid's proof
Start from the primesSeed (for a random list)
Primes listed6Product + 1–New primes–

The list of primes

✗: leaves remainder 1, so it doesn't divide the new number.

Euclid's construction

StepResult
Product…
Plus 1…
Remainders…
Factors…

Primes that divide the new number

The first k primes multiplied, plus 1

kProduct + 1Factors
13prime
27prime
331prime
4211prime
52,311prime
630,03159 × 509
7510,51119 × 97 × 277
89,699,691347 × 27,953

1/12Start from any list of primes. This one has 6: 2, 3, 5, 7, 11, 13. Euclid's proof builds a prime that isn't on it.

Watch the Python behind this model run, line by line

Product plus one isn't always prime

Objective
Correct the claim that Euclid's product plus 1 is always prime, and say what the proof needs instead.
How this step gets you there
The table under the second stage factors the product plus 1 for the first one to eight primes.

It's tempting to read the proof as saying the product plus 1 is itself a new prime. For the first one to five primes it is: 3, 7, 31, 211 and 2,311. For the first six it's 30,031 = 59 × 509, and for the first seven, 510,511 = 19 × 97 × 277. The proof only needs its prime factors to be off the list. Whether infinitely many of these numbers are prime is still unknown.

A direct proof, often told as a contradiction

Objective
Tell Euclid's original argument apart from the retelling that starts by assuming finitely many primes.
How this step gets you there
The text sets the common retelling against Euclid's own steps, in translation, and a historian's survey.

Many accounts, MacTutor's among them, call Euclid's proof a contradiction: suppose finitely many primes, multiply them, add 1. Euclid's own text, in David Joyce's translation, starts from any assigned primes A, B and C and finds one more; its only appeal to absurdity is the step showing the new prime isn't A, B or C. Romeo Meštrović's survey both uses and doubts the label. Either way, the argument builds a new prime from any list.

Eratosthenes' sieve

Objective
Say where the sieve comes from and how it lists primes without testing any number for divisibility.
How this step gets you there
The text gives the sieve's history from its sources, then ties it back to the crossing out on the stage.

The sieve is named for Eratosthenes of Cyrene, a third-century BC scholar who became librarian at Alexandria. The earliest known description is in Nicomachus of Gerasa's Introduction to Arithmetic, from the late first or early second century AD, which credits the sieve to him. It lists every prime up to a limit with no division at all: only counting along by each prime and crossing out.

How thin the primes get

Objective
Compare the sieve's prime counts with n / ln n and say what the prime number theorem claims.
How this step gets you there
The bars under the hero show the count divided by n / ln n at four limits, from the sieve's own runs.

The primes thin out but never stop. Up to 400 the sieve finds 78, where n / ln n gives 66.8. Up to 100,000 it finds 9,592 against 8,685.9, and the ratio falls from 1.161 at 1,000 to 1.104 at 100,000. The prime number theorem, proved independently by Jacques Hadamard and Charles de la Vallée Poussin in 1896, says the ratio tends to 1. Legendre and Gauss had both come to this density long before.

What the model leaves out

Objective
Say what running examples can and can't show, and where trial division and n / ln n stop being useful.
How this step gets you there
The text separates what the stage checks from what the theorems prove.

The stage proves nothing by running. It checks one list at a time and sieves only to 100,000; the proof covers every finite list at once. Trial division finds 59 in 30,031 fast, but its work grows with the square root of the number, so it is far too slow for numbers hundreds of digits long. And n / ln n is the theorem's simplest form, not its closest estimate.

Questions

Is the product of primes plus one always prime?
No. 2 × 3 × 5 × 7 × 11 × 13 + 1 = 30,031 = 59 × 509. The first five such numbers, 3, 7, 31, 211 and 2,311, are prime, and the sixth isn't. Euclid's argument only needs every prime factor of the number to be missing from the list, and that is always true.
How many primes are there below 100, 1,000 or a million?
25 below 100, 168 below 1,000, 1,229 below 10,000, 9,592 below 100,000 and 78,498 below a million. Each count is above n / ln n: 1.151 times it at 100 and 1.104 times it at 100,000.
Who proved there are infinitely many primes?
Euclid, in Book IX of the Elements, written around 300 BC. He states it without the word infinite: prime numbers are more than any assigned multitude of prime numbers. Many other proofs have followed; Romeo Meštrović's survey collects 200 of them.
Why does the sieve start crossing out at the square of each prime?
Any multiple of a prime p below p × p, other than p, is p times a number from 2 to p − 1, which has a prime factor smaller than p, so an earlier pass crossed it out. For the same reason the sieve can stop once p × p passes the limit: up to 400 the last prime it uses is 19.

More of how it works