# inverse modulo, modulo arithmetic

I was given following example in the book, however I am not sure how can the result of 27 be calculated. I realise that -13 + 40 gives 27, however how 27 ≡ −13 (mod 40) is the same as 3·(−13) ≡ 1 (mod 40) I dont really follow.

Moreover I don't really see how by Theorem ab≡cd(mod n) 3·27 ≡ 3·(−13) ≡ 1 (mod 40), I guess 3=a and c=3 by following example, ab≡cd. However it does not make much sense really.

find a linear combination of 3 and 40 that equals 1.

Step1: Divide 40 by 3 to obtain 40=3·13+1.This simples that 1=40−3·13. Step 2: Divide 3 by 1 to obtain 3 = 3·1 + 0. This implies that gcd(3, 40) = 1. Step 3: Use the result of step 1 to write

3·(−13) = 1 + (−1)40.

This result implies that −13 is an inverse for 3 modulo 40. In symbols, 3·(−13) ≡1 (mod 40). To find a positive inverse, compute 40 − 13. The result is 27, and 27 ≡ −13 (mod 40) because 27 − (−13) = 40. So, by Theorem ab≡cd(mod n) 3·27 ≡ 3·(−13) ≡ 1 (mod 40), and thus by the transitive property of congruence modulo n, 27 is a positive integer that is an inverse for 3 modulo 40. ■

Since $40 = 3 \cdot 13 + 1$, \begin{align*} 40 - 3 \cdot 13 & = 1\\ 40 + -13 \cdot 3 & = 1\\ \end{align*}

Thus, $$-13 \cdot 3 \equiv 1 \pmod{40}$$ Hence, $-13$ is a multiplicative inverse of $3 \pmod{40}$. However, so is any integer that is equivalent to $-13 \pmod{40}$. Those integers have the form $-13 + 40k$, where $k \in \mathbb{Z}$. To see this, observe that
$$(-13 + 40k) \cdot 3 \equiv -13 \cdot 3 + 40 \cdot 3k \equiv -13 \cdot 3 \equiv 1 \pmod{40}$$ In particular, if $k = 1$, then $$(-13 + 40 \cdot k) \cdot 3 \equiv (-13 + 40) \cdot 3 \equiv 27 \cdot 3 \equiv 1 \pmod{40}$$ Hence, $27$ is an inverse of $3 \pmod{40}$. Since $0 \leq 27 < 40$, it is the positive inverse we seek.

Check: $27 \cdot 3 = 81 = 2 \cdot 40 + 1 \Rightarrow 27 \cdot 3 \equiv 1 \pmod{40}$, so $3^{-1} \equiv 27 \pmod{40}$.

• thank you, i think I understand better now! – Nadia S Dec 31 '14 at 0:35
• However I am not sure I agree with so 3^−1≡27(mod40) through. as 1/3 divided by 40 does not seem to give remainder of 27. Can you please elaborate on the last statement? – Nadia S Dec 31 '14 at 0:59
• If we multiply each term in the equation $$3^{-1} = \frac{1}{3} \equiv 27 \pmod{40}$$ by $3$, we obtain $$1 \equiv 3 \cdot 27 \equiv 81 \equiv 2 \cdot 40 + 1 \equiv 1 \pmod{40}$$ Thus, $27$ is the multiplicative inverse, $3^{-1}$, of $3 \pmod{40}$. – N. F. Taussig Dec 31 '14 at 1:11

Hint $\ {\rm mod}\,\ kn\!+\!1\!:\,\ kn\!+\!1\equiv 0\,\Rightarrow\, -k\,n\equiv 1\,\Rightarrow\, n^{-1}\equiv -k.\$ Yours is case $\, k,n = 13,3.$

Generally one can use the Extended Euclidean Algorithm to compute modular inverses (above is an optimization of the single-step case). Here is a convenient way to execute the algorithm.

• Thank you for the precise answer! – Nadia S Dec 31 '14 at 0:35

The key idea you're missing, I think, is that in mod-40 arithmetic, -13 and 27 are the same number. So if -13 is the multiplicative inverse of some number, then so is 27.

Pretty much everything in that last paragraph is just an explanation for those who have not yet understood how in mod-40 arithmetic, -13 and 27 are the same number.

For example, this is what that abcd theorem is all about: if $a$ and $c$ are the same number in mod $n$ arithmetic, and $b$ and $d$ are the same number, then $ab$ and $cd$ are the same number too, since both products are doing the same thing.

Use the euclidean algorithm:

$40=3\cdot39+1\rightarrow 40-33(3)=1$

In this case you only needed one step, but it usually takes more than one step.

• You meant $40 = 3 \cdot 13 + 1 \Rightarrow 40 - 13 \cdot 3 = 1$. – N. F. Taussig Dec 29 '14 at 3:34