 This lecture is part of Berkeley Math 115, an introductory undergraduate lecture on number theory. And it will be mostly about Euler's theorem, which is a generalization of Fermat's theorem. So we quickly recall Fermat's theorem has two forms. It can either say a to the p is congruent to a modulo p, or a to the p minus 1 is congruent to 1 modulo p. Here we take p as prime, and in the second case it must be co-prime to a. And before giving Euler's generalization, I'm just going to give another application of Fermat's last theorem. And what we're going to do is to show there are infinitely many primes with last digit equal to 1. And you can see there are lots of primes like this. We have 11, 31, 61, 71, 101, and so on. And we're going to show this sequence goes on forever. This is a special case of Dirichlet's theorem, which says that if you've got any arithmetic progression, then there are infinitely many primes in that progression, unless there are obviously only a finite number. So we're doing a special case of primes of the form 10n plus 1. And we first noted that it's actually enough to show there are infinitely many primes of the form 5n plus 1, because any odd prime of the form 5n plus 1 must be of the form 10n plus 1. So we can just do infinitely many like this, and this will be easier because 5 is a prime, as we will see in a moment. So to show there are infinitely many primes like this, we're going to use the following consequence of Fermat's theorem, which says that if p divides a to the q minus 1, where p and q are prime, then either p is congruent to 1 modulo q or a is congruent to 1 modulo p. And it's easy to get muddled up about this. So the reason for this is we look at the order of a modulo p. And we notice that a to the q is congruent to 1 modulo p. So the order must divide q. You remember the order is the smallest positive power of a equal to 1, and it divides any other exponent such that a to the something equals 1. Well, since q is prime, this implies the order is 1 or the order is q. Well, if the order is 1, this means a to the 1 is congruent to 1 modulo p, which means a is congruent to 1 modulo p, which was one of the conclusions we had up there. In this case, if the order is q, we know that the p must be equal to 1 mod q because a to the p minus 1 is congruent to 1 modulo p by Fermat. So q must divide p minus 1 because the order divides this number. So this implies that p is congruent to 1 modulo q. And you notice this is the other possible conclusion. Well, we're trying to find primes that are congruent to 1 modulo something, and this sort of almost gets us there. If we take a prime dividing this, then either it's one of the primes we want or this other condition is satisfied. So we've got to somehow eliminate these ones. So what we can do is instead of looking at primes dividing x to the q minus 1, we are now going to look at primes dividing x to the q minus 1 over x minus 1. And this sort of tends to divide out primes of the form 1 modulo p, as we will see in a moment. So let's go back to this. And let's just take q equals 5 because we're trying to find primes that are 1 mod 5. So what we're going to do is we're going to look at primes dividing x to the 5 minus 1 divided by x minus 1 equals x to the 4 plus x cubed plus x squared plus x plus 1. So suppose p divides this. Well, p divides x to the 5 minus 1. So this implies that either p is congruent to 1 mod 5, which is what we want, or the other conclusion is that x is congruent to 1 modulo p. Well, if x is congruent to 1 modulo p, then this implies x to the 4 plus x cubed and so on or 1 is congruent to 5 modulo p. But since we're assuming p divides this, so this means p divides 5. So either p is congruent to 1 mod 5 or p is divisible by 5. If we also take x so that 5 divides x, then obviously p does not divide x to the 5 plus x to the 4 plus x cubed plus x squared plus x plus 1. So we've got the following conclusion that if we take any number divisible by 5, so if 5 divides x and p divides x to the 4 plus x cubed plus x squared plus x plus 1, then p is 1 modulo 5. So we can, for example, just take x equals 5 and we find 5 to the 4 plus 5 cubed plus 5 squared plus 5 plus 1 is equal to 781 and this factors as 11 times 71 and you notice these both have lost digit equal to 1 because they're 1 modulo 5 and they're odd. So now all we do is to show that infinitely many primes of the form 1 modulo 10, all we do is we take 10 x to the 4 plus 10 x cubed plus 10 x squared plus 10 x plus 1 and we take any prime p dividing this. Here x is the product of all primes we already know. And then we see that first of all p must be compared to 1 modulo 10 because we've seen it's 1 modulo 5 and it can't, or 0 modulo 5 and it can't be equal to 5 because we've put in a factor of 5 here and it can't be 2 because we put in a factor of 2 here. And secondly we also see that x is not equal to a known prime. So if we've got any collection of primes with lost digit 1 we multiply them all together, multiply by 10, form this expression here and take a prime factor of it and this will give us a new prime with lost digit 1. You notice by the way that this is an utterly useless method of finding primes in practice because if we take x to be say even something like 11 then already we're getting 100 to the power of 4 so we're getting 100 million or so and we have to factorise that to find a new prime which is obviously a really inefficient practical way of finding primes like this. However it's really good as a theoretical method. It shows there are an infinite number. So now we're going to look at Euler's generalisation of Fermat's theorem and we want to look at what is a to the power of something modulo m? So let's look at powers of a modulo m so we want to look at 1a a squared a cubed and so on modulo m. More generally we might just look at the function taking x to a times x modulo m and try and wonder how it behaves and let's just take m equals 12 and take a look and see what's going on. So the numbers modulo 12 is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 and we're just going to draw a little arrow to show what happens if you multiply each number by 2. So what we do is 0 times 2 goes to 0, 1 goes to 2, 2 goes to 4, 4 goes to 8, 8 goes to 16 which gets us back to 4, 3 gives us 6, 6 goes to 0 and then 11 goes to 10, 10 goes to 8, 9 if we double that becomes 18 which is 6. So if we look at this what we see is if we start with 2 we end up with this loop here. So if we take powers of 2 we get up to 2 cubed and then we get 2 to the 4 which is equal to 2 squared and then 2 to the 5 which is equal to 2 cubed and so on. So we've got a sort of vague analogue of Fermat's theorem except that it says 2 to the power of 4 is now equal to 2 to the power of 2. So things are getting a little bit more complicated. Well first of all we can get a weak form of Fermat's last theorem so if we're given a and m then a to the x equals a to the y for some x less than y. This is congruent modulo m, I guess I should have said. And the reason for this is you just look at all the powers of a so we start with 1 goes to a, goes to a squared, goes to a cubed and there are an infinite number of different powers, different number of possible powers but they're a finite number if we take the modulo m because they're at most n of them. So two of these must be equal. So eventually we must get some number a to the y that's actually equal to a to the x because we've got an infinite number of powers of a and we're trying to fit them into the finite number of numbers modulo m. So we've at least found, we can always find two different powers of a that are equal. Well we can do a bit better of that. Suppose that a is co-prime to m, then a is invertible. So a to the x equals a to the y or congruent to a to the y implies that a to the y minus x is congruent to 1 modulo m. So if a m equals 1, if a and m are co-prime then a to the x is congruent to 1 modulo m for sum x greater than 0. So that's the sort of, you see we've now got weak forms of Fermat's theorem so Fermat's theorem would say that a to the p minus 1 is congruent to 1 modulo p which would be a better form of this and it says that a to the p is congruent to a modulo p. So this is stronger than saying that a to the x is congruent to a to the y for sum x and y and it's stronger than saying that a to the x is congruent to 1 because we've said explicitly what these exponents x and y are in the case of primes. So what we would like to do for Euler's theorem is to make it more precise and actually identify a good power of a that is equal to 1. Well to see this, let's just look at the case of m equals 13 to get an idea of what's going on. So let's take a equals 5 and look at powers of a. So we start by looking at powers of a. Well we get 1, it goes to a to the 1 which is 5 and it goes to 25 and 25 is congruent to 12 and then 12 squared is congruent to 8 and 8 squared is congruent to 1. So we've got this little cycle of 4 numbers 1, 5, 12 and 8. So this is 1 a squared a cubed a to the 4 which is congruent to 1. Well now let's see what multiplication by a does to other numbers. So we get 2 maps to 10, 2 times 5 is 10, 10 times 5 is 50 which is congruent to 11 and 50 times 5 is 55 which is congruent to 3 and 3 times 5 we now go back to 2. And what other numbers are there? Well there's 4 and 4 goes to 7 which goes to 9, goes to 6 which goes back to 4. So what we've got is we've got the 12 numbers up to 13 are divided into these 3 cycles where if we keep multiplying by 2 we go around in these cycles. So the numbers up to 12 can be written as a union of these cycles. When you notice the cycles are disjoint, they're either disjoint or equal and that's because a is invertible. So if these 2 cycles say 2 numbers there had to be the same then obviously these 2 numbers would be the same and these 2 numbers would be the same because we can multiply by a to the minus 1. So the cycles are disjoint or the same because a is invertible. Another key point is the cycles have the same size and to see they have the same size we notice that this number here, this number here for instance is equal to 7 times a squared. Now if this number were equal to this number then we could divide by 7 and find that a squared was also equal to 1. So if 2 numbers in any cycle are the same then we can divide by 1 of the numbers and find the corresponding power of a must also be the same. And conversely if some power of a is equal to 1 then obviously all cycles have at most that size. So what we have found is the numbers co-prime to 13 mod 13 are a disjoint union of cycles and each of these cycles size the order of number 5. And since these numbers can be written as a disjoint union of cycles we see that the order of 5 must actually divide the number of numbers co-prime to 13. So we need them to be co-prime to 13 so they have inverses. You remember in order to show the cycles were either disjoint or the same we needed to actually take inverses of elements so this doesn't work if you take elements that aren't co-prime to 13. Well what we see is that this works for any number other than 13. So similarly if a is co-prime to m then the order of a divides this number 5 of m and 5 of m is Euler's phi function is the number of numbers co-prime to m. So we've now got Euler's theorem which says that a to the phi of m is common to 1 modulo m and this follows because we've shown the order of a divides this. Here we must have a co-prime to m otherwise because we need to take inverses of a in this argument and remember phi is the number of things co-prime to m. So the special case of this is Fermat if we take m equals p to be prime then we see that phi of m is just m minus 1 because the numbers 1, 2, up to m minus 1 are the numbers co-prime to m if m is prime. So this does indeed generalize Fermat's theorem. By the way what we've done we've actually proved Lagrange's theorem which says that if g is any group, well what's a group? A group is something with a multiplication that's associative and it has an identity and it has inverses a a to the minus 1 equals a to the minus 1 a equals 1. So the numbers co-prime to m have these two properties and the same argument shows that if g is a group and g is an element of the group g then the order of g divides the order of the element g divides the order of the group g and exactly the same argument we've given works for this and in particular this implies that g, the element to the power of the order of g is equal to 1 in the group g. So let's look at some examples of this. So let's just take m equals 1, 2, 3, up to 12 and take a quick look at the numbers co-prime to m. So m equals 1 is easy. We've just got 1 number 1 modulo m which we're going to take as either 1 or 0 and we notice that this number here just as order 1. If m equals 2 there's only 1 number co-prime to m and again this number here is order 1. That's rather trivial so if m is 3 we get 2 numbers which are co-prime to m and their orders are as follows. 1 is order 1 and 2 is order 2 obviously. If m equals 3, so if m equals 4, can't count, we get these numbers 1, 2, 3 and 4 and now we've got to be a bit more careful because the numbers co-prime to 4 are now 1 and 3 so we only get 2 numbers and we have, let's write down what 5m is. So 5m is 1, 1, 2, 2 and again we find the orders of these elements are 1 and 2 so they both divide 5m. So for m equals 5 we have 1, 2, 3, 4. I guess I should have put 0 in here and the numbers co-prime to 5. Sorry, I shouldn't have put 4 in there. I've got 0. The numbers co-prime to 5 are not 0, they're 1, 2, 3 and 4 and this is order 1, this is order 2 and this is order 4 because you can see that 2 squared is not 1 but 2 to the 4 is 16 which is 1 and similarly for 3 and 5m here is 4 so again we see all these orders divide 4. For m equals 6 the numbers are 0, 1, 2, 3, 4 and 5 and this time there are just 2 numbers co-prime to 6 which are 1 and 5 and you can see the orders here are 1 and 2 so 5m is 2 and again the orders all divide 2. For m equals 7 we get 0, 1, 2, 3, 4, 5, 6 so there are 6 numbers co-prime to m and now we have to start thinking a little about the orders so 1 always is order 1, 6 is minus 1 so this is order 2 we notice that 2 cubed is 8 so the powers 2 and 4 all of order 3 and 3 and 5 are left over and of order 6 so this is the case we wrote out earlier and we know 5m is 6 so all these numbers divide 6 as they ought to now in every case you see there's always a number that has the maximum possible order so here we've got order 1, here 5m is 2 and we've got something of order 2 here we've got 2 things of order 4, here we've got something of order 2 and here we've got something of order 6 so Euler's theorem gives 5m as the best possible exponent in these cases so let's look at m equals 8 so we've got these numbers 1, 0, 1, 2, 3, 4, 5, 6, 7 and the ones co-prime to 8 are just these numbers 1, 3, 5 and 7 we know 5 of 8 is equal to 4 so every element should have order at dividing 4 and if you look at the orders there are 1 and this is order 2 because 7 squared is minus 1 so you might guess the elements 3 and 5 of order 4 but in fact they both have order 2 and now something has gone wrong you see in every previous example we always found something of order equal to 5m and here there's nothing of order less equal to 5m so the orders are always less than 5 of m so Euler's theorem isn't actually always the best possible sometimes we can get a better exponent let's just do a couple more cases to finish off and see what's going on so m equals 9 we get 0, 1, 2, 3, 4, 5, 6, 7, 8 and why did m equals 8 go wrong maybe something would do with it being a prime power well let's check this prime power the numbers co-prime to 9 are just these numbers here let's work out their orders well this one is order 1 and this one is order minus 1 and if we take 2, 4, 8 well this has order 6 and this is order this is 4 has order 3 and I'm getting a bit confused about what order 5 has 2, 4, 8 8 times 2 is 7 that is order 3 and 5 has order 6 again so 5m is again 6 and we see that there are 2 elements that have order 6 which is the maximum possible and for m equals 10 this is still okay numbers are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 and the numbers co-prime to 10 are 1, 3, 7, 9 and if we work out the orders these orders are 1, 4, 4 and 2 so again 5, 10 is 4 and we've got 2 elements of order 4 so there seems to be often an element of order 5 of m well actually it's often for small numbers we'll see a bit later that for large numbers this is actually a fairly rare phenomenon these elements are called primitive roots the reason for the name primitive root comes from roots in complex analysis and I'll just sort of recall this so in complex analysis you remember the roots of unity lie in a circle and if we take something like the sixth roots of unity they all form a nice little hexagon and if we take one of these roots here then all other roots of unity are powers of this root so if we call it z then we get z squared, z cubed z to the 4, z to the 5 and z to the 6 so z to the 6 equals 1 and you notice that modulo 7 this is exactly what's happening for the primitive roots so for instance if we take this number 3 we notice that 3 to the 6 is equal to 1 so 3 is the sixth root of 1 and it's a primitive sixth root of 1 because all the other roots are powers of it so we sometimes have primitive roots of numbers and however for other numbers like 8 we don't seem to get primitive roots so we'll be examining exactly which numbers do or don't have primitive roots later in a later lecture so here's another example where you don't get the best possible results suppose you take m equals 30 and we can count the number of things co-prime to 30 and we get 1, 7, 8, 9, 10, 11, 13, 17, 19, 23, 29 so there are 8 of them so phi 30 is equal to 8 so actually 8 is common to 1 modulo 30 if x 30 is equal to 1 by Euler's theorem and is this the best possible? no it isn't and we can see it isn't best possible without actually checking all these numbers which would be a really tedious thing to do what we notice is that x to the 4 is common to 1 modulo 5 because phi of 5 is equal to 4 and x squared is common to 1 modulo 3 because phi of 3 is equal to 2 and x to the 1 is common to 1 modulo 2 because phi of 2 is equal to 1 so x to the 4 is now common to 1 modulo 2, 3 and 5 and because 2, 3 and 5 are co-prime we find that in fact x to the 4 is common to 1 modulo 30 so we can sometimes so here's another case where we can do better than Euler's theorem now I'll get finished with a couple more applications of Euler's theorem so first of all with the following problem let's find the last 2 digits of 7 to the 403 I don't know why you would want to find the last 2 digits of 7 to the power of 403 but here's how to do it if you want well what we do is we notice that phi of 100 is equal to 40 that's because these are all numbers with last digit 1, 3, 7 or 9 and it's kind of obvious that there are 40 of these so 7 to the 40 is common to 1 modulo 100 by Euler and as we remarked 40 isn't actually the best possible but whatever it's good enough for this case so 7 to the 403 is common to 7 to the 40 power of 10 times 7 cubed which is common to 7 cubed modulo 100 which is common to 343 modulo 100 so the last 2 digits of 7 to the 403 are just 43 so finally we have a sort of common recreational maths problem which is what is the last digit of let's do 7 to the 7 to the 7 to the 7 again totally pointless but it gives a sort of exercise in getting familiar with Euler's theorem well we want to know what is this modulo 10 so we have 7 to the power of something where something is this big rubbish here and we want to know 7 to the something modulo 10 well in order to work out this modulo 10 we want to know what is this something modulo 5 of 10 because we can just subtract multiples of 5 of 10 from this modulo 10 is equal to 4 and this something is 7 to the 7 to the 7 so we need to know what is this we need to know what is 7 to the 7 modulo 5 of 4 which is equal to 2 and now we can sort of work backwards we know 7 to the 7 is congruent to 1 modulo 5 of 4 so remember this is just 2 because this is 7 is congruent to 1 modulo 2 so 7 to the 7 is congruent to 1 modulo 2 so now we want to figure out what is 7 to the 7 to the 7 modulo 4 well this is congruent to 7 to the 1 modulo 4 because 7 to the 7 is congruent to 1 modulo 2 so we can replace this 7 to the 7 by this 1 because of this which is just congruent to 3 modulo 4 so now we can work out what 7 to the 7 to the 7 to the 7 is and we know that this is congruent to 3 modulo 4 so this item here is congruent to 7 to the 3 modulo 10 here we are using the fact that 7 to the 7 to the 7 is congruent to 3 modulo 4 which we have got here so all we have to do is to work out 7 cubed modulo 10 which is congruent to 343 which is congruent to 3 modulo 10 so the last digit of 7 to the 7 to the 7 to the 7 is 3 and needless to say you can't do this by working out this number explicitly because this is insanely large so next lecture I'm going to cover Wilson's theorem which says something about what factorials are modulo a prime