Prime Numbers and Euclid’s Proof


Prime Numbers and Euclid’s Proof

Anna
Let’s begin with the scale of the search. The prime number shown at the start has 687 digits, but the largest known prime as of 2024 has almost 25 million. It was discovered in 2018 and has a compact description: two to the power of 82,589,933, minus one.

Michael
That contrast is remarkable: a short formula can describe a number that would take pages and pages to write out. Another prime mentioned here is two to the power of 2,281, minus one, and it has 687 digits. Finding primes has occupied mathematicians for centuries, and although we don’t have a formula that simply generates all the primes, we do have increasingly powerful ways to find and test them.

Anna
And we know the search never ends because Euclid proved, around 300 BCE, that there are infinitely many primes. The proof starts by imagining the opposite: suppose we had a complete list of primes, which we’ll call P.

Michael
Multiply every prime in P together, then add one. Call the result Q. If Q is prime, it’s a prime missing from our supposedly complete list. If Q is composite, it must have prime factors. But none of the primes in P can divide Q: dividing the product-plus-one by any listed prime always leaves a remainder of one.

Anna
So even if Q itself isn’t prime, its prime factors must include something outside the list. Either way, the list wasn’t complete. The key fact behind that second case is that every composite number can be broken into prime factors. For example, 260 is two times two times five times thirteen.

Michael
That settles why there are always more primes to find. But how do we find them efficiently? The most straightforward idea is to try dividing a number by every smaller number. For a number like 1,000,001, that could mean testing almost a million possible divisors.

Anna
There’s a useful shortcut: divisors come in pairs. If one divisor is below the square root of a number, its matching divisor is above the square root. So if we’ve tested every possible divisor up to the square root and found none, there can’t be a divisor we missed above it.

Michael
And we can narrow the search further. Every composite number has prime factors, so when testing divisors, it’s enough to try prime numbers up to the square root—not every integer in that range. The catch is that this method assumes we already know which numbers are prime.

Anna
That’s where the Sieve of Eratosthenes comes in. Start at two, mark it as prime, and cross off its multiples as composite. Then move to the next number not crossed off, declare it prime, and cross off its multiples. Repeat until you’ve processed the range you care about.

Michael
It finds all the primes in a range much faster than testing each number independently. But sieves still become less convenient when the goal is an extremely large prime, or when we only want to test one particular number.

Anna
The Sieve of Atkin is another way to find primes in a range, and it can be a little faster. It begins with two, three, and five, then uses three quadratic expressions: four x squared plus y squared, three x squared plus y squared, and three x squared minus y squared.

Michael
For values of x and y up to a chosen limit, it examines the results using rules based on remainders modulo 60 to identify candidates. Then comes an important cleanup step: for each candidate beginning with seven, remove multiples of its square. The source describes this sieve as able to find primes up to a billion in under a second on modern computers.

Anna
But a sieve is designed to build a list from the beginning. If we have one enormous number and just want to know whether it’s prime, we can turn to primality tests. One starting point is Fermat’s Little Theorem: if p is prime, then for an integer a, a to the power of p is congruent to a modulo p. Equivalently, p divides a to the power of p minus a.

Michael
For seven, choose a equal to two. Two to the seventh minus two is 126, which is divisible by seven, so seven passes that test. But passing doesn’t prove a number is prime. For example, 341 passes when a is two, even though 341 is composite; using a equal to three reveals the problem.

Anna
Testing more values of a can make us more confident, but Fermat’s test has a serious limitation: Carmichael numbers pass it for every choice of a covered by the test, despite being composite. They’re relatively uncommon—there are 43 up to one million in the material we’re discussing—but they mean the Fermat test only identifies probable primes, not certain ones.

Michael
A stronger probabilistic method is the Miller–Rabin test. Write the candidate n minus one as two to the power of x times an odd number y. Then choose a value a and examine the remainder of a to the power of y when divided by n. If that remainder is neither one nor negative one, square it repeatedly, taking a remainder each time, and check whether negative one appears.

Anna
For 221, we have 220 equal to four times 55, so x is two and y is 55. Using a equal to 13 gives a remainder of 208. Squaring modulo 221 gives 169, and squaring again gives 52. None of those is negative one modulo 221, so this test tells us with certainty that 221 is composite.

Michael
For 37, write 36 as four times nine. With a equal to eight, eight to the ninth modulo 37 is six. Squaring gives 36, which is negative one modulo 37, so 37 passes this round. Using a equal to 11 also makes the test pass.

Anna
Passing a Miller–Rabin round still doesn’t guarantee primality. For a composite number such as 85, choosing 13 can make the test pass: 84 is four times 21, and the calculation reaches negative one modulo 85. That choice is a liar—it makes a composite number look prime.

Michael
The advantage over Fermat’s test is that no composite number passes Miller–Rabin for every possible choice of a. For any composite n, there is always a choice that exposes it. With randomly chosen values, the chance of a composite surviving one round is at most one in four; after five independent rounds, the chance is at most one in 1,024, which gives more than 99.9 percent confidence.

Anna
When probability isn’t enough, there’s the Agrawal–Kayal–Saxena test, or AKS. It uses a property of primes: for a prime p, every coefficient in the expression consisting of x plus one to the power of p, minus x to the power of p, minus one, is divisible by p.

Michael
AKS gives a conclusive answer, but conclusive doesn’t necessarily mean practical for very large inputs. The material describes it as the fastest known method for conclusively testing any number, yet says that testing a 1,000-digit number with it could take years on a modern computer. The record primes we’re interested in are far larger.

Anna
So how are those record primes found? Many of the biggest known ones are Mersenne primes: primes of the form two to the power of n minus one. The 687-digit prime from the beginning is two to the power of 2,281 minus one, and the largest known prime as of 2024 is also a Mersenne prime.

Michael
There’s an important one-way implication here. If n is composite, then two to the n minus one is composite. If n can be written as x times y, then two to the xy minus one factors into two to the x minus one, multiplied by a sum of powers of two. So it has a nontrivial factor.

Anna
But the reverse isn’t true: a prime n doesn’t guarantee that two to the n minus one is prime. For n equal to 11, the result is 2,047, which is composite. Still, the special form of Mersenne numbers makes them easier to test than a general number with the same number of digits.

Michael
Mersenne primes also connect to perfect numbers. A perfect number equals the sum of its positive divisors excluding itself; equivalently, all its divisors add up to twice the number. Six is perfect because its divisors, one, two, three, and six, add to twelve. The next examples are 28 and 496.

Anna
If two to the p minus one is a Mersenne prime, then multiplying it by two to the p minus one gives a perfect number. For example, the first Mersenne prime is three, and three times two gives six. The next is seven, and seven times four gives 28.

Michael
The factor pattern explains why. For 28, the divisors are one, two, four, seven, 14, and 28. The first three are powers of two; the others are those same powers multiplied by seven. In general, the powers of two from zero through p minus one add to two to the p minus one, and multiplying that sum by the Mersenne prime gives the sum of all the divisors. That total is twice the perfect number.

Anna
To test whether a Mersenne number is prime, we can use the Lucas–Lehmer test. Begin a sequence with four, and get each next term by squaring the previous term and subtracting two. So the sequence starts four, 14, 194, and continues.

Michael
For a Mersenne number two to the p minus one, where p is an odd prime exponent, the test looks at the term with index p minus one. If that term is divisible by the Mersenne number, the number is prime. For seven, which is two cubed minus one, we look at the second term, 14; it’s divisible by seven, so seven is prime.

Anna
The sequence grows quickly, but we don’t need to keep enormous terms. After each step, we can take the remainder modulo the candidate Mersenne number. For two to the 13th minus one, which is 8,191, the twelfth term has remainder zero, so the test confirms it’s prime.

Michael
Why does that test work? The proof uses group theory, so let’s build the basic idea. A group is a set with an operation that stays inside the set, is associative, has an identity element, and gives every element an inverse.

Anna
The integers under addition are a group: adding integers stays within the integers, addition is associative, zero is the identity, and every integer has an additive inverse. Another example is the integers from zero through nine, adding modulo ten. Five plus six is 11, which becomes one modulo ten.

Michael
A group’s order is the number of elements it contains. The order of an element is the smallest positive number of times you apply the operation to that element to return to the identity. In the modulo-ten addition group, repeatedly adding four reaches zero after five additions, so four has order five.

Anna
Repeatedly adding three reaches zero after ten additions, so three has order ten. An element’s order can’t exceed the number of elements in its group. That constraint is what the Lucas–Lehmer proof ultimately uses.

Michael
The proof also rewrites the sequence using two values: x equals two plus the square root of three, and y equals two minus the square root of three. Their product is one. The sequence’s terms can be expressed as powers of x and y; squaring a term and subtracting two produces the next term, which links this expression to the sequence’s recurrence.

Anna
Then the proof assumes a Mersenne candidate is composite and considers one of its factors, called q. It builds a finite structure from expressions involving the square root of three, with arithmetic reduced modulo q, and uses the sequence condition to constrain the order of x in a multiplication group.

Michael
That order has to be a power of two large enough to reach two to the p, but the group has fewer than q squared elements. Since q squared is no larger than the Mersenne candidate, the group is too small to contain an element with the required order. That contradiction rules out the assumed factor and establishes primality. The full proof takes care with the algebraic structure, but the central idea is using group size to make the composite assumption impossible.

Anna
Finally, the search for Mersenne primes is a team effort. The Great Internet Mersenne Prime Search, or GIMPS, was founded in 1996 by George Woltman. Volunteers run free software on their computers to test Mersenne numbers.

Michael
GIMPS had discovered the new largest known prime 15 times by the time described here, including the 2018 record found by Patrick Laroche on a home computer with a 2014 Intel processor. Even checking one Mersenne number with millions of digits can take a modern computer weeks or longer, but hundreds of thousands of volunteers together can test almost a thousand candidates a day.

Anna
So the story runs from Euclid’s proof that primes never run out, to sieves that find many primes, probabilistic tests that quickly examine individual candidates, and specialized tools such as Lucas–Lehmer for Mersenne numbers. And even those enormous primes aren’t the end of the scale: there are numbers so large that writing out their digits would require more digits than there are atoms in the universe.

Ask anything
We've read this whole study set, so questions about it get the best answers.