3

What is the multiplicative inverse of $9\pmod{37}$? I've done the Euclidean algorithm and found the gcd is $1$. I'm stuck on using the extended Euclidean algorithm. I'm confused because I'm left with $$37=(9\times 4)+1$$ and can't substitute it anywhere.

JanoyCresva
  • 486
  • 7
  • 18

4 Answers4

10

$37=9\cdot 4 + 1$ therefore $9\cdot 4 + 1\equiv 0\pmod{37}$

$9\cdot 4 \equiv -1\pmod{37}$

$9\cdot (-4)\equiv 1\pmod{37}$

$9\cdot (37-4)\equiv 1\pmod{37}$

JMoravitz
  • 79,518
4

For small numbers, you don't need the Extended Euclidean Algorithm. Just set up the required congruence and solve, choosing multipliers, relatively prime to the modulus, that successively work to force the coefficient of the unknown to get smaller and smaller in absolute value (and eventually equal to $1$). For example . . . \begin{align*} &9x \equiv 1 \pmod{37}\\[6pt] \implies\; &36x \equiv 4 \pmod{37}\\[6pt] \implies\; &-x \equiv 4 \pmod{37}\\[6pt] \implies\; &x \equiv {-4} \pmod{37}\\[6pt] \implies\; &x \equiv {33} \pmod{37}\\[6pt] \end{align*}

quasi
  • 58,772
  • Actually it's false that the coefficient will eventually reach $1$ by your method, even if there is a solution to begin with. Please see my answer for the full method. – user21820 Feb 25 '17 at 08:21
  • 1
    @user21820: Actually, as long as you multiply by numbers which are relatively prime to the modulus, there's no problem. – quasi Feb 25 '17 at 08:37
  • Right that also works. Do you mind editing your answer to add that in? It is nevertheless harder to factor the modulus than to use the Euclidean algorithm, so to avoid doing that we could test the first few primes and use whichever that are do not divide the modulus. – user21820 Feb 25 '17 at 08:58
  • No problem; I edited my answer. But note -- you don't need to factor the modulus. Just don't use multipliers that have a factor in common with the modulus. I indicated in my answer that such an ad-hoc method is recommended for the cases where the numbers are relatively small. For such cases, it works almost effortlessly. – quasi Feb 25 '17 at 09:53
  • Thanks! Yes I fully agree; I was just thinking that the normal way to test coprimality is to use the Euclidean algorithm, so to completely avoid that I suggested using primes which can be obtained by a sieve. And yes this method is convenient for small numbers especially since we can also add/subtract any two equations we have deduced. – user21820 Feb 25 '17 at 10:32
  • Very strange; someone downvoted all our answers except JMoravitz's within half a minute, despite no mathematical error as far as I can see. I don't think it's possible to read 3 answers in 30 seconds... – user21820 Feb 25 '17 at 11:55
  • @user21820 Yes I noticed it. I also got down voted. What have we done? – Juniven Acapulco Feb 25 '17 at 12:48
  • @ΘΣΦGenSan: No idea until the downvoter comes out to tell us what's wrong with our answers. – user21820 Feb 25 '17 at 12:51
  • This is what I call Gauss's algorithm - see this answer.. One can find many examples in earlier posts. – Bill Dubuque Aug 07 '17 at 01:41
  • @user21820 You are correct that this may not terminate for composite moduli. The general case can be handled using the extended Euclidean algorithm in fractional form, which is generally more efficient than Gauss's algorithm. The downvotes are puzzling but, alas, that is frequent nowadays. – Bill Dubuque Aug 07 '17 at 01:46
3

We need to find for $x$ such that $$9x\equiv 1\pmod {37}.$$ By inspection, one can see that a particular solution is $$x_0=-4.$$ So all soultions are given by $$x\equiv -4\pmod{37}.$$ But $$-4\equiv 33\pmod{37}.$$ Thus, $$x\equiv 33\pmod{37}.$$

3

The technique in quasi's answer can be proven as follows.


Take any integers $m,a,b,x$ such that $0 < a < m$ and $ax \equiv b \pmod{m}$.

If $a = 1$ then we are done so from now we assume that $a > 1$.

Let $k$ be the smallest positive integer such that $ak \ge m$.

If $ak = m$ then:

$a \mid m \mid ax-b$ and hence $a \mid b$.

  Let $c$ be an integer such that $b = ac$.

  Then $ak = m \mid a(x-c)$ and hence $x \equiv c \pmod{k}$.   [(◇) See note below.]

If $ak > m$ then:

$m > a(k-1)$ and hence $0 < ak-m < a$.

$(ak-m)x \equiv akx \equiv bk \pmod{m}$.

Therefore in all cases we have reduced the equation to be solved to a simpler one.


Note that the (◇) is not necessarily reversible. If $m$ is known to be a prime then we never use (◇) so it is alright. Otherwise we will have to check all the possible solutions at the end. Here is an example:

Take any integer $x$ such that $9x \equiv 1 \pmod{14}$.

Then $4x \equiv 2(9x) \equiv 2 \pmod{14}$.

Thus $2x \equiv 4(4x) \equiv 8 \pmod{14}$.

Thus $x \equiv 4 \pmod{7}$.

Since the original equation is modulo $14$, it suffices to check all $x$ from $0$ to $13$ that satisfies the last equation. It turns out that $11$ is a solution (but $4$ is not).

We can easily avoid this problem by using multipliers that are coprime to the modulus, as quasi suggested. However, algorithmically, how do we tell this? We could use the Euclidean algorithm for this since the multiplier is small, or we could just use small primes and check whether they are divisible by the modulus.

user21820
  • 57,693
  • 9
  • 98
  • 256