1. Home
  2. Explore
  3. Mathematics
  4. Prime Numbers and Euclid’s Proof

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

Prime Numbers and Euclid’s Proof

Transcript

This is a prime number. It has 687 digits. But  it doesn’t even come close to the biggest prime   number we know. As of 2024 the biggest prime  number we know has almost 25 million digits.   It was discovered in 2018 and despite its  size it can be easily written as 2 to the   power of 82,589,933 minus 1. Humans have  been looking for prime numbers for a very   long time. We still haven’t found the  formula for generating prime numbers.

However, we have developed methods to  discover increasingly larger primes. You might wonder how we know that we haven't yet  found all primes and there are always more prime   numbers to look for. Around 300 BCE Euclid showed  that there are infinitely many primes with this   simple proof. This proof uses the fact that every  composite number can be uniquely represented as a   product of prime numbers. For example, 260 can be  written as 2 x 2 x 5 x 13. Let’s assume that we

have found all prime numbers and contained them  in the list P. Now we can multiply all numbers   from this list and add 1 to the result to get a  number which we will call Q. This number is either   prime or composite. If it’s prime our assumption  that we have found all prime numbers was wrong.   If it’s composite, then we can write it as a  product of prime numbers. Q is not divisible   by any of the numbers in the list P, because  after dividing by any of them we get a reminder

of 1. This means there must be a number  outside the list P that is prime, so our   initial assumption was wrong, and it shows that  there are always more prime numbers to discover. Checking if a number is prime seems  straightforward: we can just see if any smaller   number divides it. However, this method is very  slow. For example, to check if 1,000,001 is prime,   in theory, we'd need to test it against 999,999  other numbers . But, there's a more efficient way

to do this using a simple fact about divisors.  Divisors always come in pairs. Knowing this   we can stop searching for divisors of a number  after we cross the square root of that number. We can also use the fact that any composite  number can be written as a product of prime   numbers. It means that we only have to consider  prime numbers when we are looking for divisors,   specifically those up to the square root of the  number. However, to apply this method, we must already have a list of which numbers are prime.  That is how the Sieve of Eratosthenes algorithm   works. Beginning with the first prime number,  2 the algorithm marks it as prime and marks off   every multiple of 2 as not prime. Then, it moves  to the next number that hasn't been marked off,   declares it prime, and marks off its multiples.  This process repeats until we label all numbers.   This method is significantly faster than  checking every number individually but still has

limitations when searching for very large prime  numbers. For those, we need something better. The Sieve of Atkin is a method that's slightly  faster for finding prime numbers. It starts with a   list already containing 2, 3, and 5. Then, it uses  three specific formulas: 4x^2 + y^2, 3x^2 + y^2,   and 3x^2 - y^2. We begin with both x and  y set to 1 and compute these formulas   and write them modulo 60. If the result of  the first formula is one of those numbers, we add that value to the list of prime  numbers. For the second formula we add   the value to the list of primes if it’s equal  to one of these numbers. And the same for the   third expression. This step is repeated for  every x and y values up to a limit we choose.

There's one more step after this. Starting  with the first number on our list after 2,   3, and 5—which would be 7—we square  it and then remove from our list every   multiple of that square. We repeat this  process with the next number in the list,   and so on. Using the Sieve of Atkin, we  can identify prime numbers up to 1 billion   in less than a second on modern computers.  However, for finding extremely large prime numbers, those with thousands of digits or  more, we need even more advanced methods. The Sieve algorithms are great for finding primes  starting at the beginning, but they aren't ideal   when we just want to know if a specific number  is prime without checking every possible divisor.   That's where Fermat's Little Theorem comes in  handy. It states that if p is a prime number,   then for any integer a smaller than p, a to  the power of p – a is divisible by p. We can

write it as a to the power of p is congruent to  a modulo p. For instance, to see if 7 is prime,   we could use 2 as our a, raise 2 to the power  of 7, subtract 2, and see that the result, 126,   is divisible by 7. So, we can conclude that 7 is  prime. Well... actually we can’t. Take the number   341: using 2 as a makes it seem prime because  2^341−2 is divisible by 341. But 341 actually   isn't prime. If we try again with a=3, we find  that 341 doesn't pass the test, indicating it's

not prime. Doing more tests with different values  of a increases our confidence in the result,   but it's still not 100% certain due to Carmichael  numbers. These numbers trick the theorem for any   a we choose, making them seem prime even though  they're not. There are relatively few Carmichael   numbers, just 43 up to 1 million, but their  existence means using Fermat's Little Theorem only   gives us "probable primes." We can't be entirely  sure we have a prime number, just highly likely.

The Miller-Rabin Test is another method to check  if a number is prime. First, we take a number n   that we want to test, and we write it as 2^x times  y + 1. Let’s say that our n is equal to 221, we   can write it as 2 to the power of 2 times 55 plus  1. Next, we pick a number a that's smaller than n,   let's say 13, and we raise it to the power of y,  which in our example is 55. This calculation would usually result in a very large number, but we're  interested in the remainder when it's divided by   n. We get a result of 208. If it’s not 1 or -1,  we square it and find the remainder once more.   208 squared mod 221 is 169. Now we only check if  it is equal to –1. 169 is not –1 so we square the   second time. In total we square it x times and  check if the remainder is –1. After squaring the   second time we get 52 modulo 221. It's not –1, so  we can conclude that 221 is not a prime number,

and we are 100% certain of it. Let’s try with  different number, for example 37. It is equal   to 2 to the power of 2 times 9 plus 1. And let a  to be equal to 8. 8 to the power of 9 modulo 37   is equal to 6. We didn’t get 1 or –1 so we square  it. And we get 36 so, it’s -1 modulo 37. So, we   can conclude that 37 is prime... probably. There  is around 1 in 4 chance that 37 is not actually   prime. To be more confident, we can test it with  different values of a. If we test it with 11, we

get that 11 to the power of 9 modulo 37 is equal  to –1. Now there is only 1 in 4 squared chance   that 37 is not actually prime. In this case 11  and 8 are witness numbers, because they say that   37 is prime and we know that it is. Now let's try  with n equal to 85 and choose a to be equal to 13,   85 is equal to 2 to the power of 2 times 21 plus  1. So, we raise 13 to the power of 21 and modulo

85 it is equal to 13. We square it, and we get  –1 mod 85. We know that 85 is not a prime number,   but 13 is saying that it is prime. In this case  13 is a liar. For every number n, there are on   average 25% liars. If we test a number n with  at least five different randomly chosen as and   they all say that n is prime, we can be 99.9% sure  that n is really prime. The Miller-Rabin test is   better than the Fermat’s test, because there are  no numbers that will look like they are prime for

all values of a. For any composite number n, there  will always be an a that shows it's not prime. The primality tests we talked about are quick but  come with a catch: they can't guarantee a 100%   accurate result. For absolute certainty, there's  a method called the Agrawal–Kayal–Saxena primality   test. This test relies on a special property:  if p is a prime number, then when you take x+1   to the power of p and subtract x to the power of  p and 1, all the coefficients in the resulting

expression are divisible by p. Thanks to some  clever improvements, the AKS test is the fastest   known method for conclusively determining if any  number is prime. However, "fast" is relative;   it's still quite slow for very large numbers. For  example, testing a number with 1000 digits using   the AKS test on a modern computer would still take  years. The biggest primes discovered so far are   much, much larger than 1000 digits. So, how were  they found and how do we know that they are prime?

The prime from the beginning of this video is  equal to 2 to the power of 2281 – 1. The largest   prime number we know is also of the form 2 to the  power of n –1. This is not a coincidence. Prime   numbers of this form are called Mersenne Primes.  The 6 biggest prime numbers we know are Mersenne   Primes. That is because there is an easy way to  test whether a number of this form is prime. The first Mersenne prime is 3, the next 7, then 31 and  so on. As you can see powers of 2 are only prime   numbers. There's a simple proof to understand  why if n is composite, then 2 to the power of   n minus 1 cannot be prime. Let's assume n is a  composite number, meaning n can be broken down   into two smaller integers x and y, neither of  which are equal 1 nor n. 2 to the power of xy   –1 can be written as 2 to the power of x –1 times  1 + 2 to the power of x + 2 to the power of 2x

up to 2 to the power of y-1 x. So, 2 to the power  of xy –1 is divisible by 2 to the power of x – 1,   so we know that if n is composite, 2  to the power of n –1 is also composite. But it doesn’t imply that if n is prime then  2 to the power of n – 1 is also prime. A clear   example of this is when n is 11: 2 to the power  of 11 minus 1 equals 2047, which is not a prime   number. Before we look on how to check whether  a Mersenne Number is prime, let’s see what the

perfect numbers are, which have a fascinating  connection to the Mersenne Primes. A perfect   number is defined as an integer that is equal to  the sum of its divisors excluding itself. Another   way to look at it is that the sum of all factors  of n equals 2n. The smallest perfect number is 6,   since its factors add up to 6, and including 6  itself, they add up to 2 times 6. Following 6, the   next perfect numbers are 28, 496, and so on. The  link between Mersenne Primes and Perfect Numbers

is quite straightforward: the nth Mersenne Prime,  when multiplied by 2^n−1, yields a perfect number.   For example, the first Mersenne prime times 2^2−1  equals 6, the first perfect number. To understand   why this relationship holds true, consider the  factors of a perfect number, like 28. Its factors   are 1, 2, 4, 7, 14 and 28. 1, 2 and 4 can be  written as powers of 2. And 7, 14, and 28 can be written as the same powers of 2 times 7, which  is the corresponding Mersenne prime. To prove that   it is always the case that we can create a perfect  number from the Mersenne primes let’s think of a   general example. In general, 2 to the n-1 times  a Mersenne prime of form 2 n – 1 is a perfect   number. Let’s write out its factors as we did with  28. So, 2 to the power of 0 + 2 to the power of 1

up to 2 to the power of n-1. And 2 to the power  of n –1 which is a Mersenne prime times the same   powers of 2. The sum of powers of 2 is just  a geometric sequence and we can calculate it   using this formula. This would be equal to 1 – 2  to the power of number of elements, which is n,   divided by 1-2. So, it is just equal to 2 to the  power of n –1. Now we factor out 2 to the n –1.   This is the sum of all divisors of our perfect  number so it should be equal to 2 times the

perfect number. And it is because if we multiply  the perfect number by 2 we get the same answer. To check if a number of the form of  2 to the power of n minus 1 is prime,   we can use the Lucas-Lehmer primality test.  It works like this: we define a sequence that   starts with 4 and the next element is always  the previous element squared minus 2. So,   the second element is 14, then 194 and so on.  To use this sequence for testing primality,

we look at the nth minus 1 term in the  sequence. If our number divides this term,   then it's prime. For example, to test if 2 to  the power of 3 minus 1 is prime, we look at   the second term in the sequence, which is 14.  Since 14 is divisible by 7, we conclude that   7 is prime. Numbers in this sequence can get very  big very fast. However, there's a trick to manage   this. Before moving on to calculate the next term  in the sequence, we can take the remainder when it's divided by our number. This step ensures  that the numbers we deal with don't get larger   than the number we're testing. For example, if we  wanted to check if 2 to the power of 13 is prime,   we would have to find the 12th number in the  sequence which is very big. But before calculating   the next term of the sequence we can just take  the remainder when dividing by our number. The   12th number in the sequence comes out to be equal  to 0, so we know that 8191 is a prime number.

To prove why this test works we will need to know  a little bit about group theory. Group theory is a   part of mathematics that studies groups, which are  collections of elements combined with a particular   binary operation (binary means that operation is  performed on 2 elements). Imagine we have a set of   all integers. From this set we can form a group G  together with addition, we could use any operation we want, we could even define our own operation,  but we will use addition for simplicity. For a   set and operation to be considered a group,  they need to meet a few criteria: Closure:   Combining any two elements using the operation  must produce another element within the same   group. For integers and addition, this is true  since adding any two integers always gives you   another integer. Associativity: The order in  which operations are performed doesn't matter.

For all a, b and c in the group. If we perform an  operation on a and b and then perform an operation   on the result and c, it should be the same as if  we first performed an operation on b and c and   then on the result of that and a. For our group  this works because addition is associative. Third:   There must be an element in the group that, when  combined with any other element, leaves the other element unchanged. It is called an identity  element. In the case of integers with addition,   the identity element is 0 because adding 0 to any  integer doesn't change that integer. And last:   Every element in the group must have an  inverse, which is another element that,   when they are combined, the result is the identity  element. For integers, the inverse of any number   is its negative because adding a number to  its negative gives 0, our identity element.

A set with a binary operation that meets  all these requirements is called a group. Let's explore another group example. Let’s define  a group X of integers modulo 10 with addition   modulo 10. This means when we add two numbers,  we take the remainder of the result when divided   by 10. For instance, adding 5 and 6 gives 11, but  in modulo 10, it's 1. This is needed to meet the   requirement of closure. The entire set of numbers  we work with in this group is all the integers from 0 to 9. The order of the group is a term that  refers to the number of elements in the group,   which in this case is 10. The order of an element  within a group is determined by how many times   we need to perform an operation with itself  to get an identity element. In other words,   the smallest integer r so that this is equal  to an identity element. In this formula,   r doesn’t denote an exponentiation. It means  that we perform the group’s operation r times,

not multiply. For example, to find the order  of the element 4 in the group X we add it to   itself repeatedly until we reach 0. The  sequence goes 4, 8, 12 which is 2 mod 10,   6, and 10 which is 0 mod 10. So, the order of 4 in  the group X is equal to 5. But we can keep going   and add more 4s. We can see that if we add 4 to  itself 10 times, we also get 0. What we know from   this is that if we perform an operation on an  element a s times, and get an identity element,

we know that s is a multiple of the order, like 10  is a multiple of 5, but 5 is also a multiple of 5.   Order is the smallest s so it’s 5. An interesting  case is the element 3. After adding it we get 3,   6, 9, 2, 5, 8, 1, 4, 7 and 0. So, the order of 3  in this group is 10. One important fact that we   will need later is that the order of an element  in a group can’t be bigger than the order of a

group. In the case of 3, its order is equal to the  order of a group. And we can see that it can’t be   bigger because to get to the identity element we  have cycled through every element of our group. To understand how the Lucas-Lehmer primality  test for Mersenne Primes works, let's start   by defining two numbers: x is 2 + the square  root of 3 and y is 2 – the square root of 3.   When we multiply x and y together, the result is  1. Now we would like to express our sequence for testing prime numbers in terms of x and y. The  nth term of the sequence is equal to the previous   term squared – 2. We can say that nth term of  a sequence is just equal to x to the power of   2 to the power of n-1 plus y to the same power.  This holds true for the first term, n=1. Now we   can show that if we square it and subtract 2 we  get the next term of the sequence. After squaring   we get x to the power of 2 to the power of n + 2  times x times y to the power of 2 to the power of

n-1 + y to the power of 2 to the power of n minus  2. x times y is just equal to 1 and 1 raised to   any power is still 1. So, the result is x to the  power of 2 to the power of n + y to the power of 2   to the power of n, which aligns with the pattern  of the sequence where n increases by 1 for each   term. So, this proves that the nth term of the  sequence can be expressed using x and y like this. We have a number Mp of form 2 to the power of p  – 1 which divides the p-1 term of the sequence and we want to prove that because of this Mp  is prime. So, we assume that Mp is not prime,   if we reach a contradiction, it will mean  that Mp is prime. If Mp divides S of p-1,   then we can write that S of p-1 is equal to some  integer k times Mp. We can represent S of p-1   using x and y. Now we can move y to the right  side of the equation and multiply both sides   of the equation by x to the power of 2 to the  power of p-2. X times y is equal to 1, so we get

this. If Mp is not prime, we can define q as the  smallest factor of Mp. Mp is equal to some power   of 2 –1 so we know that it is not divisible by  2. So, q has to be bigger than 2 and if q is the   smallest factor of Mp q squared can’t be bigger  than Mp, because factors always come in pairs. Now let’s define a set (not a group) of integers  Zq which contains all integers modulo q. Now let’s   define a set X that contains all numbers  of form a + b times the square root of 3,

where a and b are from the set Zq. We can define  multiplication in X. If we multiply 2 elements   from the set X, we get this. And after reducing  the coefficients mod q we get an element of set X,   ensuring our operation is closed within the set.  We know that q is bigger than 2 so, it means that   x is surely in set X. The size of X is equal to q  squared, because there are q possible values for a and q possible values for b, and when you consider  all combinations of a and b, you get q squared   different elements. Now we define a group X* which  contains all elements from set X that have an   inverse under multiplication. The identity element  in multiplication is 1. So, the inverse of an   element c is just equal to 1 over c. So, the only  element that doesn’t have an inverse is 0, because

we can’t divide by zero. The order of X* is  equal to q squared – 1, since it contains all the   elements of X minus the one element that can't be  inverted. We also know that x is an element of X*. If q is a divisor of Mp, then Mp is congruent  to 0 mod q. Following this logic, this equation   modulo q will just be equal to that. And if we  square both sides, we get that x to the power of   2 to the power of p is equal to 1. Which is  an identity element in multiplication. So,   we know that the order of x is a multiple of 2  to the power of p. We also know that 2 to the   power of p-1 is not a multiple of the order of x,  because x raised to the power of 2 to the power of

p – 1 is not equal to 1. So, from this we can  conclude that order of x is equal to 2 to the   power of p. Why? Here's a way to understand this:  There is a number d, and some powers of 2. If d   divides some power of 2, for example fifth power,  32 and doesn’t divide the previous power of 2,   in this case 4, we know that d is not any of the  previous powers of 2 because they all divide 16.   And we know that d has to be a power of 2 because  it divides 2 to the power of 5. So, d can only be

equal to 2 to the power of 5. We know that the  order of an element of a group can’t be bigger   than the order of a group. So, the order of x  has to be smaller or equal to the order of X*,   which is equal to q squared –1. Which is  smaller than q squared. And q squared is   smaller or equal to Mp, which is equal to 2  to the power of p – 1. 2 to the power of p   can’t be smaller than 2 to the power of p - 1. We  have reached a contradiction, so our assumption

that Mp is composite and has a factor of q was  wrong. Therefore, Mp must be a prime number. The Great Internet Mersenne Prime Search,  or GIMPS for short, is a group effort where   volunteers use free software to look for  Mersenne primes. It was founded in 1996   by George Woltman. Since its beginning, the  project has discovered the new largest known   prime number 15 times. This includes the most  recent record-breaker, found by Patrick Laroche

on December 7th, 2018. Laroche made his discovery  using an ordinary home computer equipped with   an Intel processor from 2014. Even with today's  technology, checking a Mersenne number that has   millions of digits can take a modern computer from  a week to an entire month, or even more. However,   thanks to the combined computing power  of hundreds of thousands of computers   from volunteers around the world, GIMPS can check  almost a thousand numbers for primality every day.

The prime numbers we've talked  about are incredibly large,   but there are numbers out there that  are even larger—so large, in fact,   that it's impossible to write them down. They  have so many digits that their length exceeds   the total number of atoms in the universe. To  learn more about them watch this video next.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent