Lecture 16

It would be good to know something that reassures us that there will be a solution in some family of cases, and here’s a result, named after its discovery by the ancient Chinese:

Theorem

[Chinese Remainder Theorem] Let m1m_1 and m2m_2 be coprime, and let a1a_1 and a2a_2 be any integers. The simultaneous congruences xa1(modm1)xa2(modm2)\begin{aligned} x &\equiv a_1\pmod{m_1}\\ x &\equiv a_2\pmod{m_2}\end{aligned} have a solution modulo m1m2m_1m_2.

Proving the Chinese Remainder Theorem

Proof

Suppose given m1m_1 and m2m_2 coprime.

We’ll solve two of the easiest imaginable pairs of simultaneous congruences first, and then we’ll observe that, in fact, that’s enough work to do anything.

The first easy pair of simultaneous congruences is y1(modm1)y0(modm2).\begin{aligned} y &\equiv 1\pmod{m_1}\\ y &\equiv 0\pmod{m_2}.\end{aligned} The first equation says that y=1km1y=1-km_1 for some kk, and the second says that yy is a multiple of m2m_2. In other words, we have m21km1m_2\mid 1-km_1, so km11(modm2).km_1\equiv 1\pmod{m_2}. But m1m_1 and m2m_2 are coprime, so we know we can solve this.

Another easy pair of simultaneous congruences are z0(modm1)z1(modm2).\begin{aligned} z &\equiv 0\pmod{m_1}\\ z &\equiv 1\pmod{m_2}.\end{aligned} This looks exactly the same, but the other way around: the second says that zz is of the form z=1lm2z=1-lm_2 for some ll, and the first says that zz is a multiple of m1m_1. In other words, we need lm21(modm1).lm_2\equiv 1\pmod{m_1}. We know we can do this.

In fact, instead of going through the method twice, the same process does both these pairs of congruences: if we use Euclid’s algorithm to give a solution to rm1+sm2=1,rm_1 + sm_2 = 1, in fact taking z=rm1z=rm_1 and y=sm2y=sm_2 gives us what we want:

What then of our original equations xa1(modm1)xa2(modm2)?\begin{aligned} x &\equiv a_1\pmod{m_1}\\ x &\equiv a_2\pmod{m_2}?\end{aligned} I claim that if we take x=a1y+a2zx = a_1y + a_2z, we have what we need.

Indeed, since y1(modm1)y\equiv 1\pmod{m_1} and z0(modm1)z\equiv 0\pmod{m_1}, we have x=a1y+a2za1(modm1),x = a_1y + a_2z \equiv a_1\pmod{m_1}, while, since y0(modm2)y\equiv 0\pmod{m_2} and z1(modm2)z\equiv 1\pmod{m_2}, we have x=a1y+a2za2(modm1).x = a_1y + a_2z \equiv a_2\pmod{m_1}. Both of those are exactly what we needed.

This gives us a new way of finding solutions, which I’ll show off:

What are the solutions to: x11(mod14)x10(mod17)?\begin{aligned} x &\equiv 11 \pmod{14}\\ x &\equiv 10 \pmod{17}?\end{aligned}

We’ll use our “building blocks” from the proof of the Chinese Remainder Theorem. In order to find this, we discovered we needed to invert 1717 mod 1414: we need to solve 14r+17s=1.14r+17s=1. This has a solution 5×176×14=15\times 17-6\times 14=1.

As a result 5×17=855\times 17=85 is congruent to 11 mod 1414 and 00 modulo 1717, and 6×14=84-6\times14=-84 is congruent to 00 mod 1414 and 11 modulo 1717.

Hence our solution is 11×85+10×(84)95(mod238).11\times 85 + 10\times(-84) \equiv 95\pmod{238}.

The bit in the statement which says that the moduli have to be coprime is definitely important!

Consider the following: x2(mod5)x2(mod5)\begin{aligned} x &\equiv 2 \pmod{5}\\ x &\equiv 2 \pmod{5}\end{aligned} These have a solution, but it’s x2(mod5)x \equiv 2 \pmod{5}, and not modulo 25.

On the other hand, these x2(mod5)x3(mod5)\begin{aligned} x &\equiv 2 \pmod{5}\\ x &\equiv 3 \pmod{5}\end{aligned} don’t have any solution, modulo anything.

Similarly, you can check that x17(mod30)x7(mod20)\begin{aligned} x &\equiv 17 \pmod{30}\\ x &\equiv 7 \pmod{20}\end{aligned} have a solution, which is x47(mod60)x\equiv 47\pmod{60}.

We won’t prove it, but the rules are this:

More calculations modulo primes

Earlier, we pointed out that modular arithmetic modulo primes is very well-behaved: every nonzero residue is invertible.

We’ll going to go on and use that.

The first thing we’ll talk about is exponentiation in modular arithmetic.

In integer arithmetic, it’s usually stupid to try to calculate very large powers: for example, 312343^{1234} has a huge number of digits (589589 of them, to be precise).

But, in modular arithmetic there are no large numbers. For example 312343^{1234} will be congruent to something between 00 and 99 modulo 1010, and it’s reasonable to ask what.

One very stupid way of working it out would be to do the multiplication in the integers, then divide by 1010 and find the remainder.

We can do better, by doing our arithmetic all modulo 1010 in the first place. So: 32=3×39(mod10),33=3×323×97(mod10),34=3×333×71(mod10)\begin{aligned} {}3^2 &= 3\times 3\equiv 9\pmod{10},\\ {}3^3 &= 3\times 3^2\equiv 3\times 9\equiv 7\pmod{10},\\ {}3^4 &= 3\times 3^3\equiv 3\times 7\equiv 1\pmod{10}\ldots\end{aligned} That’s still going to be a lot of multiplication, if we keep multiplying by 33 (modulo 1010) more than a thousand times!

There are considerably more intelligent ways. For example, we can square modulo 1010 quite quickly.

That lets us do some exponents by repeated squaring. For example, 38=32×4=(32)4=(32)2×2=((32)2)2.3^8 = 3^{2\times 4} = {(3^2)}^4 = {(3^2)}^{2\times 2} = {\left({(3^2)}^2\right)}^2.

1234 isn’t quite as nice, but we can do 3123432×617(32)617961792×308+1(92)3089\begin{aligned} 3^{1234} {}\equiv 3^{2\times 617} {}\equiv (3^2)^{617} {}\equiv 9^{617} {}\equiv 9^{2\times 308+1} {}\equiv (9^2)^{308}9\end{aligned} and end up getting the answer.

We’ll end up only multiplying about twenty times if we do it this way: that’s much less!

But, in fact, there’s a method that’s even faster still for this situation. We’ve just computed that 341(mod10).3^4\equiv 1\pmod{10}. That does almost all the work for us, as 34k=(34)k1k=1(mod10).3^{4k} {}= (3^4)^k {}\equiv 1^k {}= 1\pmod{10}. Hence 31234=34×308+2=34×30832=(34)30832130832329(mod10).3^{1234} {}= 3^{4\times 308 + 2} {}= 3^{4\times 308}3^2{}= (3^4)^{308}3^2 {}\equiv 1^{308}3^2 {}\equiv 3^2 {}\equiv 9\pmod{10}. That makes the whole thing easy.

The relevant observation here was really that there was some integer nn such that 3n1(mod10)3^n\equiv 1\pmod{10}. So two obvious questions are:

  1. When does there exist such an nn?

  2. When it does exist, can we compute it?

Our answer to the first is not too difficult: