3

How would I find the inverse of a given number $a$ modulo $m$, given that $\gcd(a,m)=1$?

a) $a = 2$, $m = 17$

  1. $17 = 2 \cdot 8 + 1$
  2. $2 = 1 \cdot 2 + 0$

$1 = 17 - 8 \cdot 2$

<-How do I know which one is the inverse by using back substitution?

Nicholas
  • 559
  • 1
    $9\cdot 2=18\equiv 1\pmod{17}$. We have $8\cdot 2=16\equiv -1\pmod{17}$, so $8$ is not inverse to $2$. But $-8$ works. This is congruent to $9$. – André Nicolas Mar 18 '14 at 02:11
  • How did you get from there? – Nicholas Mar 18 '14 at 02:14
  • For any odd prime $p$, the number $\frac{p+1}{2}$ is inverse to $2$, since multiplying we get $p+1$, which is congruent to $1$. As to how to get there, you could do it the slow way, by trying various things, $1,2,3,4,\dots$ until you bump into something that works. Then you may see that you could have bypassed trial and error. – André Nicolas Mar 18 '14 at 02:16
  • How did you know 8 is the inverse? – Nicholas Mar 18 '14 at 02:20
  • $8$ is not inverse to $2$, $9$ is. We can check that $9$ is by multiplying $2$ by $9$, and finding the remainder on division by $17$. If the remainder is $1$, we got the inverse. – André Nicolas Mar 18 '14 at 02:22
  • I'm confused. You said 9 is an inverse to 2. But the user below me says -8 is the inverse... – Nicholas Mar 18 '14 at 02:28
  • The two are congruent to each other modulo $17$, since $9-(-8)$ is divisible by $17$. So both are correct answers. The least positive number $a$ such that $a$ is inverse to $2$ is $9$. I mentioned $-8$ in one of my comments earlier only because your post mentioned $8$. Your calculation showed that $(8)(2)\equiv -1\pmod{17}$, so multiplying through by $-1$ we get $(-8)(2)\equiv 1\pmod{17}$. If you had not mentioned $8$, I would not have mentioned $-8$ in the comment, even though it is also a correct answer. – André Nicolas Mar 18 '14 at 02:34
  • Oh okay, so there are two correct answers: -8 and 9 as inverses. – Nicholas Mar 18 '14 at 02:36
  • 2
    There are infinitely many correct answers, for example $9+17$ is correct, also $9+34$, also $9+51$. Also $9-17$, $9-34$, and so on. But the standard things to mention are either the least positive, which is $9$, or the least in absolute value, which is $-8$. – André Nicolas Mar 18 '14 at 02:39
  • I answered almost the same question here: http://math.stackexchange.com/questions/67171/calculating-the-modular-multiplicative-inverse-without-all-those-strange-looking/67190#67190 – Michael Hardy Mar 23 '15 at 15:38
  • It is often easier to use the Extended Euclidean Algorithm, which handles the back substitution as it goes. One implementation is given in this answer. – robjohn Oct 06 '15 at 11:54

0 Answers0