Sub topic 4
Why the Primes Never Run Out
This chapter assumes you know the definition of a prime from earlier chapters. It also assumes that every integer greater than 1 has at least one prime factor, which follows from the fundamental theorem of arithmetic. You should be able to read a short Python loop and know what n % d returns.
Primes thin out as numbers grow. Between 1 and 100 there are 25 primes. Between 1,000,001 and 1,000,100 there are only a handful. That raises a fair question: do they eventually stop? Euclid answered it around 300 BCE with a proof that still works today, and it takes only a few lines.
The Argument
The proof is by contradiction. Suppose the primes are finite, and list all of them: p1, p2, ..., pk. Now build one new number:
N = p1 × p2 × ... × pk + 1
Take any prime pi from the list. Dividing N by pi leaves a remainder of 1, because the product part is an exact multiple of pi. So no prime on the list divides N.
N is greater than 1, so it must have at least one prime factor. That factor cannot be on the list, which means the list was not complete. This contradicts the assumption, so no finite list can contain every prime.
A Common Misreading
Many people remember the proof as saying "N is always a new prime." It does not say that. N is either prime itself or divisible by some prime that is missing from the list. Both cases break the assumption, and the proof never needs to know which case occurred.
You can check this directly. The code below multiplies the first few primes, adds 1, and finds the smallest factor of the result by trial division.
def smallest_factor(n):
d = 2
while d * d <= n:
if n % d == 0:
return d
d += 1
return n
primes = [2, 3, 5, 7, 11, 13]
product = 1
for p in primes:
product *= p
n = product + 1
f = smallest_factor(n)
status = "prime" if f == n else f"composite, smallest factor {f}"
print(f"up to {p:2}: N = {n:6} -> {status}")Output:
up to 2: N = 3 -> prime
up to 3: N = 7 -> prime
up to 5: N = 31 -> prime
up to 7: N = 211 -> prime
up to 11: N = 2311 -> prime
up to 13: N = 30031 -> composite, smallest factor 59The first five results are prime, which makes the misreading easy to believe. Then 30031 = 59 × 509 breaks the pattern. Both 59 and 509 are primes missing from the list {2, 3, 5, 7, 11, 13}, so the proof still holds.
What the Proof Does and Does Not Tell You
| Question | Answered by Euclid? |
|---|---|
| Are there infinitely many primes? | Yes |
| Is p1 × ... × pk + 1 always prime? | No, and it is false in general |
| How many primes lie below n? | No, the prime number theorem covers this |
| How large is the gap to the next prime? | Only a weak upper bound |
The proof tells you a sieve up to any limit will always find more primes. It says nothing about how many it will find. A later chapter answers that question with the prime number theorem.
Exercise
Let N = 2 × 3 × 5 × 7 + 1 = 211. Without dividing, explain why 211 % 5 equals 1.
Show answer
2 × 3 × 5 × 7 = 210 is a multiple of 5, so 210 % 5 = 0. Adding 1 gives a remainder of 1. The same reasoning works for 2, 3, and 7.
Exercise
Which step of the proof depends on the fact that every integer greater than 1 has a prime factor, and what would go wrong without it?
Show answer
It is the step "N > 1, so N has a prime factor q." Without that fact, the proof could conclude only that no listed prime divides N. It could not produce a prime missing from the list, so no contradiction would follow.
Exercise
Change the code to also include 17 in the primes list. Is 2 × 3 × 5 × 7 × 11 × 13 × 17 + 1 = 510511 prime?
Show answer
No. Its smallest factor is 19, and 510511 = 19 × 97 × 277. None of these primes appears in the list up to 17, which again fits the proof.