1

My aim here to learn the Chinese Remainder theorem. But am stuck at finding the inverses.

Suppose we have 42 mod 5, but according to the CRT question, we must make it 42 * x congruent to 1 (mod 5)

I know the answer is 3 by hit and trial, but can someone help me solve it using the eulidean and extended eulid alg?

3 Answers3

4

42 mod 5 is 2, so when you try to invert 42 it's the same as to invert 2 which is easier problem. Basicly, you work only with remainders: 2*0 = 0, 2*1 = 1, 2*2 = 4, 2*3 = 1, 2*4 = 3, and that's all your cases, so clearly 3 inverses 2 and so 42.

More generally, if you want to find $a^{-1}$ $mod$ $m$, you have to solve $ax+my=1$ and if solution exists, then $x$ is your inverse. Clearly it exists when $a$ and $m$ are coprimes. So, as you said, you apply extended Euclidean algorithm on $a$ and $m$ and get coefficients of Bézout's identity $x$ and $y$.

Glinka
  • 3,182
  • Can you please elaborate ax + my = 0 on, 6 * x congruent to 1 (mod 7).

    We need x.

    – Prakash Wadhwani May 01 '14 at 13:13
  • Sorry, my mistake. We solve ax+my=1, of course. I fixed it. – Glinka May 01 '14 at 13:53
  • 1 equation 2 unknowns? I still don't get that. – Prakash Wadhwani May 01 '14 at 14:01
  • Yes, and this unknowns are called Bézout coefficients. This coefficients are integers. {x=-1, y=1} is one of solutions 6x+7y=1. As -1 mod 7 = 6, then 6*6 mod 7 = 1 and 6 is inverse to itself. – Glinka May 01 '14 at 14:21
  • So basically we come back to hit and try, I don't like this. – Prakash Wadhwani May 01 '14 at 14:26
  • @PrakashWadhwani, you seem to be expecting a magic method, somehing that'll be unbelievably simple and straightforward. Expect not more: it doesn't exist. You must at least be profecient in basic modular arithmetic, which all three answers use this or that way, otherwise you won't grasp this matter in a confident way. – DonAntonio May 01 '14 at 15:22
  • "So basically we come back to hit and try", no we don't. I just don't see the point of retelling Euclidean algorithm because it would be just copypaste from this: http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm#Description_of_the_algorithm. Try to read it, it's quite simple. Besides, Oleg567 well described it and apply it directly to your problem in example. There's hardly anything left to make it simpler. Ask, if you have more specific questions. – Glinka May 01 '14 at 15:50
  • @DonAntonio I am not expecting a magic method, but I am expecting some magical explanation that can help me grasp the concept quickly. Just for your reference, go through the explanations here, and read wiki page of extended euclidean algorithm. After that watch the videos, https://www.youtube.com/watch?v=fz1vxq5ts5I and https://www.youtube.com/watch?v=shaQZg8bqUM , then tell me what to expect. – Prakash Wadhwani May 02 '14 at 06:21
  • I most certainly won't do ALL that, @PrakashWadhwani, but remember: there are also books in the Mathematics Dept (or even in the net) which you can check to complete your understanding of things. Not all is in you tube or even in wikipedia and, more important, not all the best is there. – DonAntonio May 02 '14 at 13:14
2

The CRT is not needed to find an inverse modulo a prime: it is just not what it is used for.

Here, we can do as follows:

$$42\pmod5=2\pmod5\implies 42^{-1}\pmod5=2^{-1}\pmod 5=3\pmod 5$$

Why the last equality? Because

$$\;2\cdot 3=1\pmod 5\implies 2=3^{-1}\pmod 5\;\;or\;\;3=2^{-1}\pmod 5\;$$

DonAntonio
  • 211,718
  • 17
  • 136
  • 287
  • I know its not used for that, but while solving linear congruences using CRT you need to find inverses. I am sorry but your method is way above my head. – Prakash Wadhwani May 01 '14 at 14:03
2

First, note that $42\equiv 2 (\bmod 5)$.


Extended Euclidean Algorithm (one of approaches):

When two numbers $a, m$ are given, $a<m$, $GCD(a,m)=1$, and we need to find $b$, such that $$ a\cdot b = 1 (\bmod~m),\tag{1} $$ then denote $$ r_0 = m, \qquad v_0 = 0; $$ $$ r_1 = a, \qquad\; v_1 = 1; $$ and let's find next values: $$ s_n = \left\lfloor \dfrac{r_{n-1}}{r_n} \right\rfloor; $$ $$ r_{n+1} = r_{n-1}-r_n s_n; $$ $$ v_{n+1} = v_{n-1}-v_n s_n; $$ and repeat it until $r_n=1$ $(r_{n+1}=0)$.

Last value $v_n$ (when $r_n=1$) will figure as solution of equation $(1)$.

It is comfortable to build appropriate table:

Example:

$m=1234$, $a=67$, $b=?$

$$ \begin{array}{|c|r|r|r|ll|} \hline \\ n) & r_n & v_n & s_n & \color{gray}{\mbox{check:} ~~ a \cdot v_n} & \color{gray}{\equiv r_n (\bmod~m)}\\ \hline \\ 0) & r_0=m=\color{red}{1234} & \color{red}{0} & - & & \\ 1) & r_1=a=\color{red}{67} & \color{red}{1} & 18 & \color{gray}{67\cdot 1} & \color{gray}{\equiv 67 (\bmod~1234)} \\ 2) & 28 & -18 & 2 & \color{gray}{67\cdot (-18)} & \color{gray}{\equiv 28 (\bmod~1234)} \\ 3) & 11 & 37 & 2 & \color{gray}{67\cdot 37} & \color{gray}{\equiv 11 (\bmod~1234)} \\ 4) & 6 & -92 & 1 & \color{gray}{67\cdot (-92)} & \color{gray}{\equiv 6 (\bmod~1234)} \\ 5) & 5 & 129 & 1 & \color{gray}{67\cdot 129} & \color{gray}{\equiv 5 (\bmod~1234)} \\ 6) & 1 & -221 & 5 & \color{gray}{67\cdot (-221)} & \color{gray}{\equiv 1 (\bmod~1234)} \\ \color{gray}{7)} & \color{gray}{0} & & & & \\\hline \end{array} $$

So, $b\equiv -221 \equiv 1013 (\bmod~1234)$.

Oleg567
  • 17,295
  • From what I have been watching on youtube, extended euclid algorithm is solved by substituting euclid equations in reverse order. Although this method might work on the same principle, its nevertheless confusing to me. – Prakash Wadhwani May 01 '14 at 14:10