mutliplicative inverse

Solution 1:

You can do this applying the Euclidean Algorithm.

It's pretty simple so long as you're careful with the long division :)

Once you've done the Extended Euclidean Algorithm to get the integers $x$ and $y$ such that $1 = ax + My$, then when you mod out by $M$, you get $ax \equiv 1 \pmod {M}$. Hence, whatever $x$ you get will be the multiplicative inverse of $a$.

Solution 2:

Using the Extended Euclidean Algorithm

$$\begin{array}{rrr} 342865 & 1 & 0\\ 216 & 0 & 1\\ 73 & 1 & -1587\\ -3 & -3& 4762\\ 1 & \color{#c00}{-71} & \color{#0a0}{112701}\\ \end{array}$$

where each above line $\,\ a\ \ b\ \ c\ \,$ means that $\ a = 342865\, b + 216\, c.\ $ Therefore

$$ 1 \,=\, 342865(\color{#c00}{-71})+ 216(\color{#0a0}{112701})\quad $$

from which we deduce that $\ {\rm mod}\ 342865\!:\,\ 1\equiv 216(112701),\,$ so $\,216^{-1}\equiv 112701.$

The linked post described the algorithm in great detail, in a way that is easy to remember.


Here is another example computing $\rm\ gcd(141,19),\,$ with the equations written explicitly

$$\rm\begin{eqnarray}(1)\quad \color{#C00}{141}\!\ &=&\,\ \ \ 1&\cdot& 141\, +\ 0&\cdot& 19 \\ (2)\quad\ \color{#C00}{19}\ &=&\,\ \ \ 0&\cdot& 141\, +\ 1&\cdot& 19 \\ \color{#940}{(1)-7\,(2)}\, \rightarrow\, (3)\quad\ \ \ \color{#C00}{ 8}\ &=&\,\ \ \ 1&\cdot& 141\, -\ 7&\cdot& 19 \\ \color{#940}{(2)-2\,(3)}\,\rightarrow\,(4)\quad\ \ \ \color{#C00}{3}\ &=&\, {-}2&\cdot& 141\, + 15&\cdot& 19 \\ \color{#940}{(3)-3\,(4)}\,\rightarrow\,(5)\quad \color{#C00}{{-}1}\ &=&\,\ \ \ 7&\cdot& 141\, -\color{#0A0}{ 52}&\cdot& \color{#0A0}{19} \end{eqnarray}\qquad$$

Negating the prior line we immediately deduce that, $\ {\rm mod}\,\ 141\!:\:\ \color{#0a0}{52\,\cdot\, 19}\,\equiv\, \color{#c00}1,\,$ so $\, 19^{-1}\equiv 52$