 So remember that Fermat noted that if n is prime, a solution to a to the power x congruent to 1 mod n is a divisor of n minus 1. But what if n isn't prime? To answer this, we introduce what's known as the Euler-Phe function. This was introduced by the mathematician Leonard Euler in 1763, and works as follows, let n be any whole number. Phi of n is the number of numbers less than n that are relatively prime to n. For example, let's find phi of n. We want to find the number of numbers less than 9 that are relatively prime to 9. In other words, these are numbers that have no common factors with 9. And so the numbers less than 9 are... So of these, 3 and 6 have a common divisor with 9. So we'll get rid of them. The remaining numbers, however, are relatively prime. They have no factors in common with 9, and so we find that phi of 9 is equal to 6. Similarly, we can find phi of 15, the number of numbers less than 15 that share no common factors with 15. The numbers less than 15 that share no common factors with 15 are... There's 8 of them, so phi of 15 is equal to 8. Now it's tedious to list all the numbers less than n, especially if n gets large, say, phi of 23. So we want to be able to compute it, and in fact we can compute phi of n if we have the prime factorization of n. And there's two important results to begin with. If p is prime, phi of p is p minus 1, and phi of p to the power k is p to the power k minus 1 times p minus 1. So let's find phi of 9, and we'll use the fact that 9 is 3 squared. Now since 3 is prime, then we can use our theorem. Phi of 3 squared is 3 to the power 2 minus 1 times 3 minus 1. And we compute, and we find that phi of 9 is equal to 6, which is what we found before. And a useful thing to keep in mind, anytime you have a new method, make sure it gives the same answer, in a case where you already know the answer. So we've already calculated phi of 9, we want to make sure that our formula gives us the same result. Now we know how to find phi of a prime number and phi of a power of a prime number, but what if n is not a power of a prime? And this leads to an important result. Suppose m and n are relatively prime, then phi of their product, mn, is phi of the individual values, phi of m times phi of n. So if I want to find phi of 15, we note that 15 is 3 times 5, and 3 and 5 are relatively prime. There's no number except 1 that divides them both. And so our theorem says that phi of 15 will be phi of 3 times phi of 5. But wait, there's more. 3 and 5 are actually both prime, and we know phi of a prime number is one less. And so we can compute phi of 15. And again, this is the same result we determined earlier, which is a good check on this result. So let's try it in a case where we don't already know the answer. How about phi of 20? So we begin by finding the prime factorization of 20, which will be since primes are automatically relatively prime to each other, we can write phi of 20 as phi of 2 squared times 5, and then split the prime factors, phi of 2 squared times phi of 5. We know what to do with the power of a prime, so phi of 2 squared, that's 2 to the 2 minus 1 times 2 minus 1. And since 5 is prime, we also know how to find phi of a prime number, it's one less. And so that gives us, and let's check this out one last time. So the numbers less than 20 that are relatively prime to 20 are, and we see that phi of 20 is actually 8 as computed. The importance of the Euler-Phi function is that Euler extended Fermat's result to the following, suppose a is relatively prime to n, then the least power x that solves a to power x congruent to 1 mod n is a divisor of phi of n. So for example, suppose we want to solve 18 to power x congruent to 1 mod 1,081, and we'll take a hint here that 1,081 is 23 times 47. So the least solution will be a divisor of phi of 1,081. So we find phi of 1,081, using the hint that 1,081 equals 23 times 47, we find. Now 23 and 47 are both prime, so we can find these values. And since we want to find the divisors of this number, it's convenient to leave it in prime factored form. So 22 is 2 times 11, and 46 is 2 times 23. And so by taking some or all of these numbers and multiplying them together, we can find our divisors. So if we take a single number, our divisors are 2, 11, 23. If we take two numbers at a time, we get the factor 4, 22, 46, and 253. If we take three numbers at a time, we get 44, 92, and 506. And if we take all four numbers at once, we get 1,012. And the important thing here is that the least solution has to be one of these numbers. And so we try them out, 18 to the second, fourth, eleventh, and so on. And we find 253 is our least solution. And let's see why this is important. When we solve this congruence, we use the hint that 1,081 was 23 times 47, and this allowed us to solve by trying out a few possibilities. Without the hint, we'd have to try out every possibility. We'd have to find 18 to the second, 18 to the third, 18 to the fourth, 18 to the fifth, 18 to the sixth, 18 to the seventh, and so on, and eventually we'd get to our solution 18 to the 253rd. And it's worth comparing these. Instead of testing nine numbers, which is what we did when we had the hint, we need to test 252. And the value of that is that solving 18 to the power x congruent to 1 mod 1,081 is a hard problem that's easy if you have a hint. And what's important is that these are exactly the types of problems we use when we create a cryptographic system. Hard problems that are easy with one additional piece of information.