1
$\begingroup$

I need to find out the modular inverse of 5(mod 11), I know the answer is 9 and got the following so far and don't understand how to than get the answer. I know how to get the answer for a larger one such as 27(mod 392) but am stuck because they are both low numbers.

11=5 (2)+1

5=1 (5)

$\endgroup$
1
$\begingroup$

In finding a modular inverse, you are trying to solve the modular equation $$ ax\equiv 1\pmod n. $$ Ordinarily, you use the Extended Euclidean Algorithm for this to solve the equation $ax+ny=1$. If the numbers $a$, and $n$ are small, then simple trial and error is probably just as fast or faster.

For your example, we have $a=5$ and $n=11$, which means would could just use trial and error. \begin{align} 1\cdot 5 &\equiv 5\\ 2\cdot 5 &\equiv 10\\ 3\cdot 5 &\equiv 15\equiv 4 \\ 4\cdot 5 &\equiv 20\equiv -2\\ 5\cdot 5 &\equiv 25\equiv 3 \\ 6\cdot 5 &\equiv 30\equiv -3 \\ 7\cdot 5 &\equiv 35\equiv 2 \\ 8\cdot 5 &\equiv 40\equiv -4 \\ 9\cdot 5 &\equiv 45\equiv 1 \\ 10\cdot 5 &\equiv 50\equiv -5 \\ \end{align}

Since $9\cdot 5 \equiv 1$ then we have found the modular inverse to be 9.

When looking at those numbers on the far right side, keep in mind that any multiple of 11 made be added or subtracted to the modulus and it is still equivalent. That is, $-3\equiv 30\equiv 8$ since $-3+3(11)=30$ and $8+2(11)=30$.

$\endgroup$
  • $\begingroup$ ok I haven't seen this way of doing it before so could you help clarify something for me: on the left you have (x) x a than the sum of it in the middle, and on the right you have how much its over a multiple of 11 ( a positive number) or how much it is under a multiple of 11 ( a negative number) $\endgroup$ – user2956865 Aug 7 '14 at 17:43
  • $\begingroup$ Read the line from left-to-right. So we could have (for the line $4\cdot 5\equiv 20\equiv -2$), 4 times 5 equals 20. But we want the remainder after this is divided by 11. Since $20 = 11+9$, this means $20\equiv 9$ (the part that isn't a multiple of 11). But I like smaller numbers, so I'm going to subtract 11 from this to get $9-11=-2$ which means $20\equiv -2$. Since it's not 1, then this means that 4 is not the modular inverse. $\endgroup$ – Lee Aug 7 '14 at 17:51
  • $\begingroup$ ok thanks lee that helped to clear it up $\endgroup$ – user2956865 Aug 7 '14 at 17:57
2
$\begingroup$

Hint $\ $ mod $\,ab\!+\!1\!:\,\, ab \equiv -1 \,\Rightarrow\, a(-b) \equiv 1.\ $ Yours is $\,a,b = 5,2.$

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.

$\endgroup$
1
$\begingroup$

You can use your work to get $1=11-5(2)=11+5(-2)$,

so an inverse of 5 (mod 11) is given by $-2\equiv9\pmod {11}$.

$\endgroup$
  • $\begingroup$ Ok I've been trying to work it out differently trying to use the this way I saw in youtube video, so how do you go from 1=11-5(2)=11+5(-2) to -2= 9 (mod 11) $\endgroup$ – user2956865 Aug 7 '14 at 17:31
  • $\begingroup$ The equation $1=11+5(-2)$ shows that -2 is an inverse of 5 (mod 11), and then you can add 11 (or any multiple of 11) to get other inverses of 5 (mod 11). $\endgroup$ – user84413 Aug 7 '14 at 17:48
0
$\begingroup$

Here is a piece of C code that you might find useful:

int Inverse(int n,int a)
{
    int x1 = 1;
    int x2 = 0;
    int y1 = 0;
    int y2 = 1;
    int r1 = n;
    int r2 = a;

    while (r2 != 0)
    {
        int r3 = r1%r2;
        int q3 = r1/r2;
        int x3 = x1-q3*x2;
        int y3 = y1-q3*y2;

        x1 = x2;
        x2 = x3;
        y1 = y2;
        y2 = y3;
        r1 = r2;
        r2 = r3;
    }

    return y1>0? y1:y1+n;
}

Calling Inverse(11,5) returns 9.

Calling Inverse(392,27) returns 363.

$\endgroup$
  • $\begingroup$ thanks that could come in handy in future, I just needed to know how to do it by hand so I'm able to do it in a exam $\endgroup$ – user2956865 Aug 7 '14 at 17:55
  • $\begingroup$ @user2956865: You're welcome. I think that the algorithm above is the same thing that you'll be doing manually. $\endgroup$ – barak manos Aug 7 '14 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.