Lecture 17

Powers congruent to 11


Let aa and mm be coprime integers. Then there is some positive nn such that an1(modm).a^n\equiv 1\pmod{m}.


There are only mm different residues modulo mm, so some two of the sequence 1,a,a2,a3,a4,,am1,a,a^2,a^3,a^4,\ldots,a^m must be congruent modulo mm (they can’t all be different).

Let’s say that aiaj(modm)a^i\equiv a^j\pmod{m}, with i<ji<j.

But aa is invertible modulo mm, and so (a1)iai(a1)iaj(modm),(a^{-1})^ia^i\equiv (a^{-1})^ia^j\pmod{m}, which gives that aji1(modm).a^{j-i}\equiv 1\pmod{m}.

That proof is a little bit nonconstructive: it tells us it exists, but doesn’t give very much help looking for it.

It turns out that that we can get an explicit result. First we’ll do a relatively easy case, valid when the modulus is prime.


[Fermat’s Little Theorem] Let pp be prime, and let aa be an integer coprime to pp. Then ap11(modp).a^{p-1}\equiv 1\pmod{p}.

Before we prove it, we’ll talk a while longer about invertible elements and multiplication modulo a prime.

Let’s start with an example, and consider the seven integers 0,3,6,9,12,15,18.0,3,6,9,12,15,18. Regarded modulo 7, each is congruent to something different: 00184151125926633\begin{aligned} {0}&{\equiv 0} & {18}&{\equiv 4} \\ {15}&{\equiv 1} & {12}&{\equiv 5} \\ {9}&{\equiv 2} & {6}&{\equiv 6} \\ {3}&{\equiv 3} &&\end{aligned} Can we explain this systematically?

It comes down to the fact that 33 is invertible modulo 77 (with inverse 55, as 3×51(mod7)3\times 5\equiv{1}\pmod{7}).

By multiplying congruences, 3×5×aa(mod7)3\times 5\times a\equiv a\pmod{7} so if we want to solve 3xa(mod7)3x\equiv a\pmod{7}, we simply take x5a(mod7)x\equiv 5a\pmod{7}.

So as there are seven numbers in the list, and one is congruent to each possible residue 0,1,,60,1,\ldots,6 (modulo 7), they’re all different.

This is true in general, for the same reason: if aa is coprime to mm, then the integers 0,a,2a,,(m1)a0,a,2a,\ldots,(m-1)a contain each of the mm residues (and so exactly once each, because there’s mm of them).


Consider the product a(2a)(3a)((p1)a),a\cdot(2a)\cdot(3a)\cdot\cdots\cdot((p-1)a), regarded up to congruence modulo pp.

One way of thinking about it is that it’s (p1)!(p-1)! but with every term multiplied by an aa, so is congruent to ap1(p1)!a^{p-1}(p-1)!.

Another is that, since the product contains a copy of every nonzero residue modulo pp, it is congruent to (p1)!(p-1)!.

But, putting these observations together, we discover that ap1(p1)!(p1)!(modp).a^{p-1}(p-1)! \equiv (p-1)!\pmod{p}. But all the residues from 11 to p1p-1 are invertible, and the product of invertible residues is invertible, so (p1)!(p-1)! is invertible. Multiplying both sides by (p1)!1(p-1)!^{-1} leaves us with ap11(modp),a^{p-1}\equiv1\pmod{p}, exactly as promised.

Fermat’s Little Theorem should not be confused with Fermat’s Last Theorem. The latter says there are no solutions in positive integers to an+bn=cna^n+b^n=c^n with n3n\geq 3, and was much, much harder to prove.

In the proof of Fermat’s Little Theorem, we multiplied one representative of each invertible residue class together. It turns out we can prove a substantially more general theorem, but it’s a little more complicated. First we need a definition:
Definition: Euler’s function (sometimes known as the totient function) φ:NN\varphi:\mathbb{N}\rightarrow\mathbb{N} is defined by taking φ(n)\varphi(n) to be the number of integers from 11 to nn which are coprime to nn.

For example, φ(p)=p1\varphi(p) = p-1 if pp is prime, since every number from 11 to p1p-1 is coprime to pp (and pp isn’t coprime to pp).

For another example, φ(6)=2\varphi(6) = 2, since 11 and 55 are the only numbers between 11 and 66 which are coprime to 66.

Using this concept, we can generalise Fermat’s Little Theorem considerably:


[Fermat-Euler Theorem] Let aa and nn be integers with gcd(a,n)=1\gcd(a,n)=1. Then aφ(n)1(modn).a^{\varphi(n)}\equiv 1\pmod{n}.


The proof is exactly the same as Fermat’s Little Theorem, but instead of working with all the integers 1,2,,n11,2,\ldots,n-1, we just consider those that are invertible modulo nn: let’s write these as x1,x2,,xφ(n)x_1,x_2,\ldots,x_{\varphi(n)}.

If aa is invertible, then ax1,,axφ(n)ax_1,\ldots,ax_{\varphi(n)} are all invertible too, and any invertible residue is of this form: bb can be written as a(a1b)a(a^{-1}b). Hence ax1,ax2,,axφ(n)ax_1,ax_2,\ldots,ax_{\varphi(n)} are congruent to x1,x2,,xφ(n)x_1,x_2,\ldots,x_{\varphi(n)} in some order.

Hence if we consider the products of these we have x1x2xφ(n)(ax1)(ax2)(axφ(n))aφ(n)x1x2xφ(n)(modn)\begin{aligned} & x_1x_2\cdots x_{\varphi(n)}\\ \equiv& (ax_1)(ax_2)\cdots(ax_{\varphi(n)})\\ \equiv& a^{\varphi(n)}x_1x_2\cdots x_{\varphi(n)}\pmod{n}\end{aligned} Since all the elements x1,x2,,xφ(n)x_1,x_2,\ldots,x_{\varphi(n)} are invertible, we can cancel them out to get aφ(n)1(modn)a^{\varphi(n)}\equiv 1\pmod{n}.