0

I asked this before, but unfortunately, I didnt know the methods, nor was the questions phrased properly.

Find the inverse of $4258 \pmod{147}$ Using Euclidean Extended Algorithm.

Begin By Stating the remainders (Euclid's Algorithm):

$4258 = 28(147) + 142$

$147 = 1(142) + 5$

$142 = 28(5) + 2$

$5 = 2(2) + 1$

Then BACK substitution starting with $1$:

$1 = 5 - 2\cdot 2$

$1 = 5 - 2\cdot \bigg(142 - 28(5)\bigg ) = -279 + 2\cdot 28(5)$

$1 = -279 + 2\cdot 28\bigg( 147 - 142 \bigg)$

$1 = -279 + 56 \cdot \bigg( 147 - 4258 + 28(147) \bigg)$

But how would I proceed?

Amad27
  • 10,465

3 Answers3

1

In your back substitution you're collapsing some things too much.

In the second back-sub line you should have $1$ as a combination of $5$ and $142$. That is $$1=5-2\cdot\left(142-28(5)\right)=5\cdot(57)-142\cdot(2)$$.

In your next line you should sub in $5=147-142$ and get $1$ as a combination of $147$ and $142$.

And so on.

paw88789
  • 40,402
  • Let me understand something. For Euclid's algorithm, I start with what? $4258$ or $147$? I have seen some starting with $m$ where $\pmod{m}$ but otherwise as well? how would I begin? – Amad27 Jan 25 '15 at 11:02
  • You should get the same answer either way. It's a little quicker to start with the larger number. – paw88789 Jan 25 '15 at 11:04
  • So then: If you get: 4258 = x(quotient) + remainder the next step is: quotient = x(remainder) + remainer_2 ?? – Amad27 Jan 25 '15 at 11:05
  • Your section 'Begin by stating the remainders' is a good set up. – paw88789 Jan 25 '15 at 11:07
  • Okay, so I do this then: $4258 = 147(z) + R_1$ Then: $z = R_1(y) + R_2$ .... ? – Amad27 Jan 25 '15 at 11:08
  • @Amad27: Your second step should be $147=R_1\cdot y+R_2$--just like you have it set up in your question. – paw88789 Jan 25 '15 at 11:16
1

Actually each remainder in the euclidean algorithm satisfies Bézout's identity. Let's start with $r_0=4258, r_1=147$. If $r_{i+1} $ is the remainder at the $i$-th step (dividing $r_{i-1}$ by $r_i$), write $r_i=u_i \cdot 4258+v_i\cdot147$. Let $q_i$ be the corresponding quotient. The algorithm translates into the relations: $$u_{i+1}=u_{i-1}-q_iu_i,\qquad v_{i+1}=v_{i-1}-q_iv_i$$ These relations allow for computing progressively all Bézout's coefficients without having to revert back. This is the Extended Euclidean Algorithm. Here is how it goes in the present case:

$$ \begin{array}[t]{r@{\qquad}r@{\qquad}r@{\qquad}r} r_i &u_i &v_i & q_i\\ \hline 4258 & 1 & 0 & \\ 147 & 0 & 1 & 28\\ \hline 142 & 1 & -28 & 1\\ 5 & -1 & 29 & 28 \\ 2 & 29 & -840 & 2 \\ 1 & -59 & 1709 \\ \hline \end{array} $$

So $-59\times4258+1709\times 147=1$, which implies $4258^{-1}=-59=88 \bmod 147$.

Bernard
  • 175,478
0

The Algorithm:

  • Input: $n=147,a=4258$
  • Set $x_1=1$
  • Set $x_2=0$
  • Set $y_1=0$
  • Set $y_2=1$
  • Set $r_1=n$
  • Set $r_2=a$
  • Repeat until $r_2=0$:
    • Set $r_3=r_1\bmod{r_2}$
    • Set $q_3=\lfloor\frac{r_1}{r_2}\rfloor$
    • Set $x_3=x_1-{q_3}\cdot{x_2}$
    • Set $y_3=y_1-{q_3}\cdot{y_2}$
    • Set $x_1=x_2$
    • Set $x_2=x_3$
    • Set $y_1=y_2$
    • Set $y_2=y_3$
    • Set $r_1=r_2$
    • Set $r_2=r_3$
  • If $y_1>0$ then output $y_1$
  • Otherwise output $y_1+n$

C-Implementation:

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;
}

int result = Inverse(147,4258); // 88
barak manos
  • 43,109