# Simple linear congruence question

Where did the following argument go wrong? (The correct answer in $\mathbb{Z}_{100}$is just $81$.)

Working mod 100: $$21x\equiv1$$ $$105x\equiv5$$ $$5x\equiv5$$ $$x\equiv1,21,41,61,81$$

Thank you.

-

## 6 Answers

$$a \equiv b \pmod{c} \implies ka \equiv kb \pmod{c}$$ where $k \in \mathbb{Z}$ is always true. However, $$ka \equiv kb \pmod{c} \implies a \equiv b \pmod{c}$$ is true only when $\gcd(k,c) = 1$.

For instance, $$21x \equiv 1 \pmod{100} \implies 105 x \equiv 5 \pmod{100}$$ is true. But $$105x \equiv 5 \pmod{100} \implies 21 x \equiv 1 \pmod{100}$$ is false.

Let us now look at where you have made the mistake in your computation.

EDIT

In your solution, you are finding $x$ such that $$5x \equiv 5 \pmod{100}$$ i.e. $$105x \equiv 5 \pmod{100}$$ However, this does not imply that $$21x \equiv 1 \pmod{100}$$ Only a subset of the values that satisfy $5x \equiv 5 \pmod{100}$ will satisfy $21x \equiv 1 \pmod{100}$

-
Hi Marvis. What you wrote is exactly what I understood, and seems to be consistent with the working presented in my question above! So what was my mistake up there (since you say that it's okay to multiply both sides by 5) ?? – Ryan Oct 27 '12 at 23:14
@Ryan I have updated the solution. Let me know if it makes sense. – user17762 Oct 27 '12 at 23:21
YES!! This was exactly what I needed spelt out in my cloud of confusion. When the responses here collectively indicated that multiplying both sides by an integer was disallowed, I got more bewildered, trying to reconcile the apparent contradiction with what I understood to be one of the fundamental properties of congruences. However, what was wrong was not the multiplying both sides per se but the fact that when solving an eqn, every step requires an "iff." to be sure that excess solutions aren't being created.... – Ryan Oct 28 '12 at 7:07
...For some inexplicable reason, this basic and elementary fact had entered my blind spot. Thank you, Marvis. – Ryan Oct 28 '12 at 7:08
@Ryan Good to know that you understood. – user17762 Oct 28 '12 at 7:09

Your mistake was multiplying by $5$, which does not have a multiplicative inverse modulo $100$. You can see the problem even more clearly if you try to solve $20x\equiv1\pmod{100}$ that way: you get $100x\equiv5\pmod{100}$, but of course $100x\equiv0\pmod{100}$, so we have $5\equiv0\pmod{100}$, which is clearly nonsense. You’re entitled to multiply both sides of a congrence $\pmod m$ by $a$ iff $a$ has a multiplicative inverse $\pmod m$, which is the case iff $a$ and $m$ are relatively prime.

To solve $21x\equiv1\pmod{100}$ you can either rely on ad hoc methods or simply use the Euclidean algorithm to find $\gcd(21,100)$:

\begin{align*} 100&=4\cdot21+16\\ 21&=1\cdot16+5\\ 16&=3\cdot5+1\;, \end{align*}

and working back up the chain, we get

\begin{align*} 1&=16-3\cdot5\\ &=16-3(21-16)\\ &=4\cdot16-3\cdot21\\ &=4(100-4\cdot21)-3\cdot21\\ &=4\cdot100-19\cdot21\;. \end{align*}

Thus, $100\mid 1-(-19)(21)$, so $21(-19)\equiv1\pmod{100}$, and $x\equiv-19\pmod{100}$ is the solution. You probably want the representative that’s in $\{0,\dots,99\}$, so you’d probably rather write it $x\equiv-19+100=81\pmod{100}$. (There are shortcuts for carrying out the calculations above; I left them in their most self-explanatory form.)

For an ad hoc approach I’d probably notice that $21\cdot19=20^2-1=399\equiv-1\pmod{100}$, so $21(-19)\equiv1\pmod{100}$.

-
Thanks, Brian! I particularly love that insight in the last line. Number theory is such an art form!:) – Ryan Oct 28 '12 at 7:29
@Ryan: You’re welcome. – Brian M. Scott Oct 28 '12 at 15:36

When you multiplied by $5$, the nonsolutions entered. $21$ is relatively prime to $100$, so it has a unique multiplicative inverse $\pmod{100}$. If $d$ has common divisor with $m$, then $dx\equiv a \pmod{m}$ may not have or may have exactly $m/\gcd(m,d)$ solutions.

I would do something like (all $\pmod{100}$): \begin{align} 21x & \equiv 1 \equiv -99\\ 7x &\equiv -33 \equiv 67 \equiv 567 \\ x &\equiv 81 \end{align}

-
Am I allowed to multiply both sides only by an integer that's not coprime with 100? However, my course notes state the following rule for solving linear congruences: (1) If we multiply one side of a congruence by m, say, then we must also multiply the other side by m. – Ryan Oct 27 '12 at 22:43
It is allowed to multiply. But nonsolutions may enter. Similar to squaring. – Berci Oct 27 '12 at 22:49
Oh! Thanks for the intuition. – Ryan Oct 27 '12 at 22:56
@Ryan: Yes: you want to be sure that the operation is reversible, which means that $d$ must have a multiplicative inverse $\pmod m$, which in turn means that $\gcd(d,m)$ must be $1$. – Brian M. Scott Oct 27 '12 at 23:07
@Brian Thanks, Brian. – Ryan Oct 28 '12 at 7:11

Hint $\rm\displaystyle\ \, mod\ 100\!:\ \, x\equiv \frac{1}{21}\equiv\frac{1}{121}\equiv\left(\frac{1}{11}\right)^2\!\equiv 81\ \ \ by\ \ \ \frac{1}{11}\equiv\frac{9}{99}\equiv\frac{9}{-1}$

Your error is $\rm\:x\equiv y\iff 5x\equiv 5y.\:$ $(\Rightarrow)$ is true but $(\Leftarrow)$ is false, e.g. $\rm\:5\cdot 20\equiv 5\cdot 0\:$ but $\:20\not\equiv 0$.

Remark $\$ As above, for "small" manual computations of inverses and fractions, non-algorithmic methods often are quickest since, by the law of small numbers, there are frequently enough coincidences to make the problem easily massaged into one where the inverse or quotient is obvious. Generally one can resort to algorithms such as the Extended Euclidean algorithm (see here for a very convenient manual way to apply it) and Gauss' algorithm.

-
Thanks Bill. I use this unorthodox shorthand working too when solving simple quadratic congruences. But I hadn't thought of using this to find multiplicative inverses. I'm not completely confident of using this outside of solving quadratic inverses though, so I will probably still use the extended Euclidean algo or by ad hoc to find multiplicative inverses for now. And thank you for pointing out the error in my working above. Cheers. – Ryan Oct 28 '12 at 7:24
@Ryan $(1)$ It's not unorthodox. If you study abstract algebra (localizations) then you will learn that this is a consequence of the universality of fraction arithmetic. Said informally, for the ring of integers, computations with fractions remain valid in any ring where the denominators are invertible. – Bill Dubuque Oct 28 '12 at 15:22
@Ryan $(2)$ E.g. the above computation is valid because all denominators $\rm\,d\,$ that occur are coprime to $100$ so they are invertible mod $100,\,$ i.e. there is a unique $\rm\, d^{-1},\:$ so the fraction $\rm\,c/d = c\,d^{-1}\,$ denotes a unique element mod $100,\,$ and one easily verifies that the usual formulas for fraction arithmetic remain valid (when restricted to fractions with invertible denominators). Thus, quite widely, we can reuse our prior intuition on fractions to simplify arithmetic. – Bill Dubuque Oct 28 '12 at 15:23
Yes, that makes sense. Thanks. – Ryan Oct 28 '12 at 19:40

The problem with the process shown in your question is that everything was multiplied by a zero divisor ($5\cdot20\equiv0\pmod{100}$). This loses information (though not as much information as is lost when multiplying by 0).

The Euclidean Algorithm is the systematic way to do this, but to keep track of things, I use the Euclid-Wallis Algorithm, which combines the Euclidean Algorithm with some ideas from continued fractions. $$\begin{array}{r} &&4&1&3&5\\\hline 1&0&1&-1&4&-21\\ 0&1&-4&5&-19&100\\ 100&21&16&5&1&0\\ &&&&{\uparrow}&{\star} \end{array}$$ What this shows is that $4\cdot100-19\cdot21=1$. That is, the inverse of $21\bmod{100}$ is $-19\equiv81\pmod{100}$.

-

$$21x\equiv 1\pmod{100}\Rightarrow 105x\equiv 5\pmod{100}\Rightarrow5x\equiv 5\pmod{100}$$ Then instead of $$x\equiv1\pmod{100}$$ you should have $$x\equiv1\pmod{\frac{100}{5}}$$ i.e. $$x\equiv1\pmod{20}.$$ So you have the candidates $1,21,41,61,81$.

-