 So, there's one trait that all great creative artists have in common. They are very, very, very prolific. Now one way to do that in math is to find different proofs for the same result. And so Euler proved Fermat's theorem in 1736 via induction, in 1742 using a different induction argument, in 1755 using the proof we presented, and a fourth time in 1758 using a slightly different approach. Now the important thing about Euler's 1758 proof was that he considered the case where the modulus wasn't prime. As we saw, in that case the powers of A might form a closed set that doesn't have one as the identity. But if we want to talk about subgroups they do need to have the same identity, and so you can't talk about identities without breaking up inverses. And so we might remember that A has a multiplicative inverse mod n, if and only if A and n are relatively prime. So let's consider the powers of a number relatively prime to the modulus. So again let's consider, suppose A is relatively prime to n. The sequence A, A squared, A cubed, and so on must eventually have A to the power m congruent to A to the power n, which means their difference has to be a multiple of n, and we can factor. And when n was prime we use this factorization to conclude that n had to divide this A to m minus n minus 1. But well, n is relatively prime to A, and so that means it's also relatively prime to A to the n, which means that it has to divide A to the m minus n minus 1. And so again there is a least solution to A to the power x congruent to 1 mod n. What do we know about the least power for which A to the power x is congruent to 1 mod n? So let's think about that. First of all, all terms in the sequence 1, A, A squared, and so on up to A to the power k minus 1 must be relatively prime to our modulus, n. And so that means that k is at most equal to the number of numbers relatively prime to n. So mathematicians do like using symbols, so Gauss introduced the notation to refer to the number of numbers less than n that are relatively prime to n. Now the symbol has two different pronunciations. It's a Greek letter, and if you're Greek you would pronounce this phi. So this would be phi of n. However, most people pronounce this phi, and so they talk about phi of n. They have the same thing just with different accents. So we saw earlier that if n was prime, then the least solution to A to the power x congruent to 1 mod n is a divisor of n minus 1. If n is composite, we can modify our proof very slightly to obtain the following, which is known as the Euler Fermat theorem. Let A and n be relatively prime. The least solution to A to the power x congruent to 1 mod n is a divisor of phi of n, the number of numbers relatively prime to n. Now, this is the fourth time Euler proved Fermat's theorem, although Euler extended the result so much that it can't properly be called Fermat's theorem anymore, and we typically refer to it as the Euler Fermat theorem. Most of the 1758 paper was actually focused on the properties of this phi function. And there are some easy results. So if p is prime, then phi of p is going to be p minus 1. Similarly, if p is prime, phi of p to the k is p to the k minus p to the k minus 1. And that has a quick proof. If I imagine the numbers in the sequence 1, 2, 3, and so on up to p to the k, then every p-th number has a factor in common with p. And so if we eliminate these numbers, then p to the k minus p to the k minus 1 numbers remain. Euler next considered the problem of what happens if p and q are distinct primes. What's phi of p times q? And to answer this question, Euler considered the following array. Our first row will consist of the numbers 1, 2, 3, up to p minus 1. For the second row, we'll add p to all of these numbers. For the next row, we'll add p again. And we'll continue that until we get up to qp minus 1 as our last number of the last row. Now, the important thing to realize is that since p and q are primes, every number in this array is relatively prime to pq. And so that means phi of pq is the number of numbers in this array. Well, the array has p minus 1 columns and q minus 1 rows. And so phi of pq is the product p minus 1 times q minus 1. Now, if we imagine our array to be constructed as follows as a table, where our column labels are the numbers from 1 to p minus 1, and our row labels are the numbers from 1 to q minus 1, then nothing important changes if we use the numbers relatively prime to p as the column labels and the numbers relatively prime to q as the row labels. And Euler makes this change and concludes that if a and b are relatively prime, then phi of ab is phi of a times phi of b. And if we put all of these things together, we now know how to calculate phi of any numbers. phi of n, the number of numbers less than n that are relatively prime to n, satisfies the following properties. If n is a prime number, phi of n is just n minus 1. Also, phi of a power of n is n to the k minus n to the k minus 1. And if m and n are relatively prime, phi of the product is the product of the phi values. So for example, let's find phi of 40. So our theorem tells us that we can find the phi for a composite number by breaking it up into a product of relatively prime factors. And so we note that 40 is 2 to the 3rd times 5. And so phi of 40 is phi of 2 to the 3rd times 5. We can split that phi of 2 to the 3rd times phi of 5. 2 to the 3rd is a power of a prime number. And so that phi value is going to be 2 to the 3rd minus 2 to the 2nd. 5 is prime, so phi of 5 will be prime minus 1. And after all the best settles, we find that phi of 40 will be 16. And once we know how to find the phi values, we can solve congruences like 7 to the power x congruent to 1 mod 40. And so by the Euler Fermat theorem, the least solution must be a divisor of phi of 40, which we already found to be 16. And so the only possibilities for a solution are going to be things that are divisors of 16. 1, 2, 4, 8, and 16. And we can find those directly. 7 to the 2nd, that's 49, which reduces down to 9. 7 to the 4th, well, that's 7 to the 2nd times 7 to the 2nd. And the advantage of working mod n is you never have to work with large numbers. We know that 7 to the 2nd is 9. And so 7 to the 4th is 1. And so there's our solution.