# Lecture 15

Even if you don’t want to do division in modular arithmetic, you still have to be careful about cancellation.

In ordinary arithmetic over the integers, we know that $ax=ay$ implies $x=y$ (provided that $a$ isn’t zero, of course). This is true even though we don’t know how to divide integers in general.

But we can’t always cancel in modular arithmetic: the third example above tells (for example) that $2\cdot 3\equiv 2\cdot 7\pmod{8}$, but that $3\not\equiv 7\pmod{8}$.

Here’s a fact, mostly a repackaging of some observations we made in a previous lecture, about diophantine equations, saying when we can divide $1$ by things in modular arithmetic.

#### Proposition

Let $a$ and $m$ be integers. There is an integer $b$ such that $ab\equiv 1\pmod{m}$ if and only if $\gcd(a,m)=1$.

When such a number $b$ does exist, it’s unique (modulo $m$).

#### Proof

We deal with existence first.

Using Bezout’s lemma, we know we can find integers $b$ and $c$ such that $ab+mc=1$ if and only if $\gcd(a,m)\mid 1$.

But $\gcd(a,m)\mid 1$ if and only if $\gcd(a,m)=1$, and the equation $ab+mc=1$ says exactly that $ab\equiv 1\pmod{m}$.

Now we deal with uniqueness.

Suppose that we have two numbers $b$ and $b'$ such that $ab\equiv 1\pmod{m}$ and $ab'\equiv1\pmod{m}$. Then $b \equiv b1 \equiv b(ab') \equiv (ba)b' \equiv 1b' \equiv b'\pmod{m},$ which shows uniqueness modulo $m$.

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

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

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

There are a few exceptions:

• The inverse of $1$ modulo $m$ is always

$1$.

• The inverse of $-1$ modulo $m$ is always

$-1$.

• If $m$ is odd, then $2$ is invertible modulo $m$, because $\gcd(m,2)=1$. The inverse is:

$(m+1)/2$.

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

#### Proposition

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

#### Proof

We have $aa^{-1}\equiv 1\pmod{m}$, which says that $a$ is an inverse for $a^{-1}$.

#### Proposition

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

#### Proof

We have $(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 $37$, modulo $100$. We want $x$ with $37x\equiv 1\pmod{100}$. In other words, we seek a solution to $37x+100k=1$ in the integers. We’ll get one from working through Euclid’s algorithm: \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 \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)\times 37\equiv 1\pmod{100}$, so the inverse of $37$ is $-27$, which is congruent to $73$ (mod $100$).

### Checking our working

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

## The Chinese Remainder Theorem

We’ve come to understand congruence equations: given something like $123x \equiv 456\pmod{789},$ we can, with some effort, turn it into something nice like $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, \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 \begin{aligned} x-1 &= 4a\\ x-3 &= 7b,\end{aligned} for some numbers $a$ and $b$.

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

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

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

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

There need not always be solutions to simultaneous congruences. For example, the simultaneous congruences \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 $x$ even, the second $x$ odd.

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