 A useful strategy in mathematics at life, if there are m objects to be placed in n locations with m greater than n, then at least two objects must be in the same location. This is known as the pigeonhole principle. If we have more pigeons than pigeonholes, then at least one pigeonhole must contain more than one pigeon. One of the important uses of the pigeonhole principle is actually proving Fermat's theorem. So remember that Fermat claimed, suppose P is a prime number and A is not a multiple of P, then the least solution to A to the power x congruent to one mod P will divide P minus one. Now like so many Fermat's results, he didn't actually provide a mathematical proof. And so Euler would provide a partial proof in 1736 and then prove it three more times throughout his life. So in a 1761 proof, results of remainders left by division of powers, Euler made the following argument. Consider the infinite sequence of powers, one A, A squared, A cubed, and so on. Since there's only a finite number of possible remainders, two of the terms have to have the same remainder when divided by P. Now while Euler actually talked about D remainders, we would now say that the two terms must be congruent mod P. Now suppose A to M is congruent to A to N mod P, where we'll assume that M is greater than N. Then because they're congruent, P has to divide their difference A to the M minus A to the N. But since we've assumed that M is greater than N, we can factor out A to the N from this difference. And remember that if a prime divides a product, it must divide one of the factors. So P has to divide either A to the N or A to the M minus N minus 1. But since we've assumed P is prime and A is not multiple of P, then P can't divide A to the power N, and so it must divide A to the power M minus N minus 1. And so that means A to the power M minus N is congruent to one mod P. Now suppose K is the least power for which A to the power K is congruent to one mod P. If we consider the numbers, they must all be different mod P. And the reason is as follows. If they're not, then we'd have two of them congruent mod P, where M and N in this case are both less than K. Now at this point we can make basically the same argument that we made for showing that there is a power congruent to one, but we'll do something a little bit different this time to work in some congruences. So we know that A to the M is congruent to A to the N. So the difference is congruent to zero. We can still factor. And since A and P are relatively prime, we know that A has a multiplicative inverse, and so A to the N also has a multiplicative inverse, so we can get rid of A to the N, and that tells me that A to the power M minus N is congruent to one, which contradicts our assumption that K was the least power for which A to the power K was congruent to one. Now the fact that they're all different is actually very useful. So let's find all possible remainders of four to the power K mod 17, and then find four to the power 50 mod 17. So we find the powers of four, mod 17, and since four to the fourth is congruent to one, any higher power can be reduced, and so four to the fiftieth can be reduced, too. And so now let's introduce a flock of pigeons. If K is the least power for which A to the power K is congruent to one, then all of these terms are all different mod P. Now since A to the power N can't be congruent to zero for any N, then there's only P minus one possible values here. Now notice there's actually K values, and so if K is not equal to P minus one, then there has to be some number r where A to the N is not congruent to r. So now consider the values r, rA, rA squared, and so on, essentially what we get by multiplying the terms of the first sequence by r. This must all be distinct mod P. You should prove that. What's important is they must also be different from the terms of our first sequence mod P, and we can prove that as follows. Suppose rA to the M is congruent to A to the M. Well, there's two possibilities. Either M is less than N, or M is greater than N. So if M is less than N, we have, and this contradicts our assumption that r is not equal to A to the N. If M is greater than N, we have, and this contradicts our assumption that r is not equal to A to the N. So now we have two sets of remainders. This set, our original set, and this set, our new set. And again, each set contains K different remainders. So if all remainders are included between the two sets, 2K has to equal P minus one. If we don't have all remainders, then there's some number S, where A to the N is not congruent to S, and rA to the N is not congruent to S. And now we lather, rinse, repeat. So we'll consider S times each of the terms of the first sequence. And again, they're all different. And they must be different from the other sets as well. And so now we have three sets of remainders. So if we found all the remainders, then 3K has to be P minus one. If it doesn't, then there's some number T. And now we'll lather, rinse, repeat. And that tells us that P minus one is equal to QK for some number Q. Consequently, if A to the power K is congruent to one mod P, and K is the least power for which this is true, then K is a divisor of P minus one. So for example, we found the powers of four mod 17 were 1, 4, 4 squared, and 4 to the third. Now, 5 is not one of these. So if we multiply each of these by 5, we get a new set of remainders, 5, 3, 12, and 14. So again, we have our second set of remainders. And we know that 2 is not among this set. So we'll multiply our original sequence by 2. And if we look through our list, we see that 6 is not among these. So we multiply by 6. And now we have all possible remainders, mod 17. And they've been split up into four sets of four.