Lecture 15

When there is a number bb such that ab1(modm)ab\equiv 1\pmod{m}, we call it the inverse of aa, modulo mm (and we say that aa is invertible). We write a1a^{-1} for the inverse of aa.

Notice that, as a consequence modular arithmetic modulo a prime pp is fantastically well-behaved: any nonzero residue a≢0(modp)a\not\equiv 0\pmod{p} has an inverse (since we have gcd(a,p)=1\gcd(a,p)=1 unless aa is a multiple of pp).

Spotting inverses modulo mm is quite difficult; in general the best way is to use Euclid’s algorithm.

There are a few exceptions:

Two other fairly easy, but useful, facts are as follows:


If aa is invertible modulo mm, then so is a1a^{-1}, with inverse given by (a1)1a(modm)(a^{-1})^{-1} \equiv a\pmod{m}.


We have aa11(modm)aa^{-1}\equiv 1\pmod{m}, which says that aa is an inverse for a1a^{-1}.


If aa and bb are both invertible, then abab is too, with inverse given by (ab)1b1a1(modm).(ab)^{-1} \equiv b^{-1}a^{-1}\pmod{m}.


We have (ab)b1a1aa1bb1111(modm)(ab)b^{-1}a^{-1} \equiv aa^{-1}bb^{-1} \equiv 1\cdot 1\equiv 1\pmod{m}.

As a big example of all of this, let’s find an inverse for 3737, modulo 100100. We want xx with 37x1(mod100)37x\equiv 1\pmod{100}. In other words, we seek a solution to 37x+100k=137x+100k=1 in the integers. We’ll get one from working through Euclid’s algorithm: 100=2×37+2637=1×26+1126=2×11+411=2×4+34=1×3+13=3×1.\begin{aligned} {100} & {= 2\times 37+26}& {37} & {= 1\times 26 + 11}\\ {26} & {= 2\times 11+4}& {11} & {= 2\times 4+3}\\ {4} & {= 1\times3+1}& {3} & {= 3\times1.}\end{aligned} So we have that 1=1×41×3=1×41×(112×4)=3×41×11=3×(262×11)1×11=3×267×11=3×267×(3726)=10×267×37=10×(1002×37)7×37=10×10027×37.\begin{aligned} {1 = 1\times4-1\times3} & {= 1\times4-1\times(11-2\times 4)}\\ {= 3\times4-1\times11} & {= 3\times(26-2\times11)-1\times11}\\ {= 3\times26-7\times11} & {= 3\times26-7\times(37-26)}\\ {= 10\times26-7\times37} & {= 10\times(100-2\times37)-7\times37}\\ {= 10\times100-27\times37.}\end{aligned} That means that (27)×371(mod100)(-27)\times 37\equiv 1\pmod{100}, so the inverse of 3737 is 27-27, which is congruent to 7373 (mod 100100).

Checking our working

And, of course, we can check this easily: 37×73=27011(mod100)37\times 73 = 2701\equiv 1\pmod{100} as claimed.

The Chinese Remainder Theorem

We’ve come to understand congruence equations: given something like 123x456(mod789),123x \equiv 456\pmod{789}, we can, with some effort, turn it into something nice like x132(mod263).x\equiv 132\pmod{263}.

Now we’ll discuss a different sort of problem with congruences: what if we have two of them for the same number? For example, x1(mod4)x3(mod7)?\begin{aligned} x &\equiv 1\pmod{4}\\ x &\equiv 3\pmod{7}?\end{aligned} These things happen all the time: two things happening periodically with different periods.

And it turns out we can solve them using exactly the same machinery as we’ve been using all along. Indeed, these equations say that x1=4ax3=7b,\begin{aligned} x-1 &= 4a\\ x-3 &= 7b,\end{aligned} for some numbers aa and bb.

That means that 1+4a=3+7b,1+4a=3+7b, or in other words 4a7b=24a-7b=2. We have lots of experience solving these, and, since gcd(4,7)=1\gcd(4,7)=1, it’s possible.

A solution to 4a7b=14a-7b=1 is given by a=2a=2, b=1b=1, and so a solution to 4a7b=24a-7b=2 is given by doubling that to get a=4a=4, b=2b=2.

What’s the general solution? Well, if we have 4a7b=24a-7b=2, then subtracting 4×47×2=24\times4-7\times2=2 gives 4(a4)7(b2)=0.4(a-4)-7(b-2)=0. This means that 74(a4)7\mid 4(a-4), so 7(a4)7\mid(a-4). Hence aa is of the form 7k+47k+4. and in fact any such aa works.

Now, we had x=4a+1x=4a+1, which in turn is 28k+1728k+17. In other words: x17(mod28).x\equiv 17\pmod{28}.

There need not always be solutions to simultaneous congruences. For example, the simultaneous congruences x4(mod6)x3(mod8)\begin{aligned} x &\equiv 4 \pmod{6}\\ x &\equiv 3 \pmod{8}\end{aligned} don’t have solutions. Why is this obvious?

The first equation implies xx even, the second xx odd.

Of course, if we go through the same solution process as above it will fail. We set x=4+6ax=3+8b\begin{aligned} x &= 4 + 6a\\ x &= 3 + 8b\end{aligned} and find that 4+6a=3+8b4+6a = 3+8b, and hence 8b6a=18b-6a=1. This has no solutions because gcd(8,6)=2\gcd(8,6)=2, and 212\nmid 1.