-1

I have a math problem, that I've been trying to solve. It has literally took me at least 10 hours, and I just can't understand one part of this. I've been watching videos that explain these things but usually they use more simple numbers and the whole thing is much shorter so it doesn't get me very far.
The problem itself and where I'm currently stuck on:

Find the inverse of $359 \bmod 457.$

$$33 + 32(-1) = 1 $$ $$65 + 33(-1) = 32 $$ $$98 + 65(-1) = 33 $$ $$359 + 98(-3) = 65 $$ $$457 + 359(-1) = 98 $$

And after this backwards:

$$33 + [65 + 33(-1)](-1) = 1$$
$$33 + 65(-1) + 33 = 1 $$ $$2(33) + 65(-1) = 1 $$ $$2[98 + 65(-1)] + 65(-1) = 1 $$ $$2 ยท 98 + 65(-2) + 65(-1) = 1 $$ $$2(98) + 65(-3) = 1 $$

I know that I need to apply $359 + 98(-3) = 65$ next, and $457 + 359(-1) = 98$ after that but I just can't understand this.
I would assume that next lines would be something like this:
$$2(98) + [359 + 98(-3)] = 261 $$ but this doesn't look right to me because of the answer. I've been really frustrated with this problem.

Thank you in advance.

thesmallprint
  • 3,636
  • 1
  • 16
  • 25
  • Most all the complexity of backward substitution disappears if you do the extended euclidean algorithm in the forward direction - see the first linked dupe. See also the others for many other often easier methods to compute modular inverses and fractions. โ€“ Bill Dubuque Apr 04 '23 at 18:09

3 Answers3

1

Firstly, you apply Euclid's algorithm on $359$ and $457$. We have $$457=359\cdot 1+98,$$ $$359=98\cdot 3+65,$$ $$98=65\cdot 1+33,$$ $$65=33\cdot 1+32,$$ $$33=32\cdot 1+1,$$ $$32=1\cdot 32+0.$$ So $\text{gcd}(457,359)=1$; that is, $359$ does have a multiplicative inverse modulo $457$. In order to find this, it suffices to find $u$ and $v$ such that $$359u+457v=1.$$ We do so by running this algorithm backwards.

\begin{align}1&=33-32\cdot 1\\ &=33-(65-33)\\ &=33\cdot 2-65\\ &=(98-65)\cdot 2-65\\ &=98\cdot 2-65\cdot 3\\ &=98\cdot2-(359-98\cdot3)\cdot3\\ &=98\cdot 11-359\cdot3\\ &=(457-359)\cdot11-359\cdot3\\ &=457\cdot11-359\cdot14. \end{align}

Thus, $u=-14$ and $v=11$.

So, the inverse of $359\bmod 457$ is $-14$, or equivalently, $443$.


So basically what happened in your attempt is you missed the (-3) that multiplies the 65 term when substituting your equivalent expression for 65.

thesmallprint
  • 3,636
  • 1
  • 16
  • 25
0

There are two things:

Thing One:

You are trying to find some $A,B$ so that $359A + 457B = 1$.

Once you find those you know that $359 A = 1 - 457B$ so $359A \equiv 1 \mod 457$.

And so $A \equiv 359^{-1}$.

(We don't actually care about $B$.)

Thing Two:

You got:

$33 + 32(-1) = 1$

$65 + 33(-1) = 32$

$98 + 65(-1) = 33$

$359 + 98(-3) = 65$

$457 + 359(-1) = 98 $

(Presumably you worked this in the opposite order.)

You can use these to figure out Thing One.

A) $33 + 32(-1) = 1$ and $65 + 33(-1) = 32$

So $33 + (65 + 33(-1))(-1) = 1$ or

$33(2) + 65(-1) = 1$.

B) And we have $98 + 65(-1) = 33$

So $(98 + 65(-1))(2) + 65(-1) = 1$ or

$98(2) + 65(-3) = 1$

C) And we have $359 + 98(-3) = 65$.

So $98(2) + (359 + 98(-3))(-3) = 1$ or

$98(11) + 359(-3) = 1$

D) And we have $457 + 359(-1) = 98 $

So $(457 + 359(-1))(11) + 359(-3) = 1$ or

$457(11) + 359(-14) = 1$

And that's the $A$ and $B$ we needed for Thing One.

.....

$457*11 + 359*(-14) = 1$ so

$359*(-14) \equiv 1 \mod 457$

And $359^{-1} \equiv -14 \equiv 443 \mod 457$

....

If you wish to verify:

$359*(-14) = -5026 = 1 - 5027 = 1 - 11*457$.

Which in turns means $359*443 = 359*457 - 359*14 = 359*457 - 5026 = 1 + 359*457 -5027 = 1 + 359*457 - 11*457 = 1 + 348*457$.

fleablood
  • 124,253
0

We can also use the extended Euclidean algorithm.

Define $457 = (1,0)$ and $359 = (0,1)$. $359$ divides into $457$ once, which leaves $98 = (1,-1)$.

Now $359$ is equal to three times $98$ with remainder $65$. This gives $65 = (0, 1) - 3(1, -1) = (-3, 4)$.

$98$ equals one copy of $65$ with remainder $33$. This gives $33 = (1, -1) - (-3, 4) = (4, -5)$.

And now, note that $65 - 2 \cdot 33 = -1$. This gives $-1 = (-3, 4) - 2(4, -5) = (-11, 14)$, or that $1 = 11 \cdot 457 - 14 \cdot 359$.

Hence $11 \cdot 457 - 14 \cdot 359 = 1$ implies that $-14 \cdot 359 \equiv 1 \pmod {457}$, taking the modulo of $457$ on both sides. This means the inverse of $359$ is $-14$, which is the same as $-14 + 457 = 443$.

Toby Mak
  • 16,827