0

I'm trying to find the modular inverse of 28 mod 45 with the Euclidean algorithm but I'm getting the wrong answer. According to online calculators, the answer is $37$, but I'm getting $42$, here are my steps, where am I messing up? Thanks in advance.

Euclidean algorithm: $$45=28\left(1\right)+17$$

$$28=17\left(1\right)+11$$

$$17=11\left(1\right)+6$$

$$11=6\left(1\right)+5$$

$$6=5\left(1\right)+1$$

Then I rearrange the bottom 3 equations: $$6-5\left(1\right)=1$$ $$11-6\left(1\right)=5$$ $$17-11\left(1\right)=6$$

Substitute for $5$ in the $6-5(1)=1$ equation:

$$6-\left(11-6\left(1\right)\right)\left(1\right)=1$$ $$6-11+6=1$$ $$2(6)+11(-1)=1$$

And finally, substitute the $6$ to get my answer of $42$:

$$2\left(17-11\left(1\right)\right)+11\left(-1\right)=1$$ $$2\left(17\right)+11\left(-3\right)=1$$ $$45-3\ =\ 42$$

Bill Dubuque
  • 272,048
  • Hello and welcome to math.stackexchange. You are not done yet. You need to arrive at an equation of the form $28s + 45t = 1$ with integers $s$ and $t$. Continue substituting, using all equations, – Hans Engler Apr 24 '21 at 14:57
  • @HansEngler oh dang! that's a tedious processes, thank you! – i am bad at coding Apr 24 '21 at 15:00
  • You want your last part when finding $28s +45t = 1$. So you want to start where you did with $1$ and work backwards to get the $s$ and $t$. You'll see $45t \mod45 \equiv 0 \mod45$, so your inverse will be $s$. – James Apr 24 '21 at 17:18
  • To avoid such headaches stop doing it backwards! Instead use the simpler forward form. – Bill Dubuque Apr 24 '21 at 18:20
  • @BillDubuque thanks for the new approach! though I'm having a difficult time understanding how it looks – i am bad at coding Apr 24 '21 at 23:56
  • @PSUChange See the last example in my prior link, with the equations listed. What is not clear to you there? – Bill Dubuque Apr 24 '21 at 23:59
  • @BillDubuque how do you change the numbers from one line to the next? I don't see a relationship. if you could do it with my numbers here that'd be amazing, ill accept it as answer – i am bad at coding Apr 25 '21 at 00:02
  • The row operations are extensions of the Euclidean algorithm algorithm operations as explained in the master post linked there, e.g see "for example $ 62-3(18) = 8$ ..." there. – Bill Dubuque Apr 25 '21 at 00:06
  • @BillDubuque ooh thank you! – i am bad at coding Apr 25 '21 at 00:08
  • And see this comment there. Is it clear now? If so you should see how much simpler it is propagating the equations forward vs backward. – Bill Dubuque Apr 25 '21 at 00:11
  • Applied to your problem: $$\rm\begin{eqnarray} [![1]!]\ \ \ \ , 45\ &=&,\ \ 1&\cdot& 45, +\ 0&\cdot& 28 \ [![2]!]\ \ \ \ \ 28\ &=&,\ \ 0&\cdot& 45, +\ 1&\cdot& 28 \ [![1]!]-2,[![2]!], \rightarrow, [![3]!]\ \ {-}11\ &=&,\ \ 1&\cdot& 45, -\ 2&\cdot& 28 \ [![2]!]+2,[![3]!],\rightarrow,[![4]!]\quad\ \ \ 6\ &=&,\ \ 2&\cdot& 45, -\ 3&\cdot& 28 \ [![3]!]+2,[![4]!],\rightarrow,[![5]!]\quad\ \ \ \color{#c00}1\ &=&,\ \ 5&\cdot& 45, -\ \color{#0a0}8&\cdot&\color{#0a0}{28} \end{eqnarray}\qquad\qquad\qquad$$ – Bill Dubuque Apr 25 '21 at 01:12
  • Reducing the prior Bezout equation $\bmod 45!:\ \color{#c00}1\equiv \color{#0a0}{-8\cdot 28},$ so $,28^{-1}\equiv -8\equiv 37.,$ Note that we used a smaller negative remainder ($-11$ vs. $17$) in row $ [![3]!]$ to shorten work - see this remark. – Bill Dubuque Apr 25 '21 at 01:20
  • @BillDubuque yep! I got it, thank you! it is a easier approach. will save me a lot of time! time to impress my friends lol. – i am bad at coding Apr 25 '21 at 02:31

4 Answers4

2

I don't know where does the last line come from. From$$2\times17+(-3)\times11=1,$$you should get that$$2\times17+(-3)\times(28-17)=1,$$or$$5\times17-3\times28=1.$$And now$$5\times(45-28)-3\times28=1,$$or$$5\times45-8\times28=1.$$So, the inverse of $28$ mod $45$ is $-8$, or $37$.

1

Work backwards as follows: \begin{align*} 1&=6-5=6-(11-6)\\ &=2\cdot6-11=2\cdot(17-11)-11\\ &=2\cdot17-3\cdot11=2\cdot17-3(28-17)\\ &=5\cdot17-3\cdot28=5\cdot(45-28)-3\cdot28\\ &=5\cdot45-8\cdot28, \end{align*} so $28(-8)=1\bmod45$.

yoyo
  • 9,943
1

Here is the standard layout of the extended Euclidean algorithm, which yields the coefficients of a Bézout's relation between $28$ and $45$. It uses the fact that each remainder $r_i$ in the algorithm satisfy a Bézout's relation $\;u_i\, 28+v_i\,45=r_i$ and that these coefficients satisfy the recurrence relation of order $2$ $$u_{i+1}=u_{i-1}-q_iu_i,\qquad v_{i+1}=v_{i-1}-q_iv_i, $$ where $q_i$ is the quotient in the $i$-th division. \begin{array}{r|rr|l} r_i&u_i&v_i&q_i \\\hline 45 & 0 & 1 \\ 28 & 1 & & 1 \\ \hline 17 & -1 & 1 & 1 \\ 11 & 2 & -1 & 1 \\ 6 & -3 & 2 & 1 \\ 5 & 5 & -3 & 1 \\ \hline 1 & \color{red}{-8} & \color {red}5 \end{array} so the relation is $$-8\cdot 28+5\cdot 45=1$$ and therefore $\;28^{-1}\bmod 45=-8\equiv 37$.

Bernard
  • 175,478
1

NOT AN ANSWER BUT FOOD FOR THOUGHT.

Alternatively (although not Euclidean Algorithm exactly):

$28$ goes into $45$, $1$ times with $17$ left over so: $1\cdot 28 \equiv -17 \pmod {45}$

$17$ goes into $45$, $2$ times with $11$ left over so: $2\cdot 1\cdot 28 \equiv 2(-17)\equiv -34 \equiv 11 \pmod {45}$

$11$ goes inot $44$, $4$ times with $1$ left over so: $4\cdot 2\cdot 1\cdot 28 \equiv 4\cdot 11 \equiv 44 \equiv -1 \pmod {45}$

So $-4\cdot 2\cdot 1\cdot 28 \equiv 1\pmod 45$

And $-4 \cdot 2 \cdot 1\equiv -8\equiv 37 \equiv 28^{-1} \pmod {45}$.

This differs from the classical Euclidean Algorithm in that the remainder always divides into the original modulus rather than the previous quotient. Has an advantage that you you have a straight product which is easier to calculate than a seriers of sums and products. Not sure why this isn't done more or why I never noticed it before.

... oh, I guess I see the bug....

Consider

$28 \equiv -17 \pmod {45}$

$3\cdot 28 \equiv -51 \equiv -6\pmod {45}$

$21 \cdot 28 \equiv -42 \equiv 3 \pmod {45}$

$(15\cdot 21)\cdot 28 \equiv 45 \equiv 0 \pmod {45}$

And $15\cdot 21 \equiv 45 \cdot 7 \equiv 0\pmod {45}$.

By dividing into the original modulus we make no assurance that the remainders are relatively prime to the original modulus.

We can make a rule that you only multiply be terms relatively prime to the modulus but that defeats the original purpose of EA to find out what is the gcd of terms.

Still as we know $45 = 5\times 3^2$ and $\gcd(28, 45)=1$ this is easy to work. Of course if you have an number lots of factors, say $360$, the the rule, don't multiply by any multiple of $2,3,5$ makes this method impractical.....

Oh, well. I thought it worked so well......

fleablood
  • 124,253