I am able to solve simpler linear congruences, for example $3x \equiv 2 \pmod 5$. What I would do in this case is use that $0 \equiv 10 \pmod 5$ and then utilising a theorem: $3x \equiv 12 \pmod 5$. Then I can divide by $3$ leaving me $x \equiv 4 \: \left( \mathrm{mod} \: {\frac{5}{\mathrm{GCD}(5,3)}} \right) \quad \Longleftrightarrow x \equiv 4 \pmod{5}$ which means the solution is $x = 4k + 5$ where $k \in \mathbb{Z}$.

But I cannot apply the same method to this congruence: $$ 32x \equiv 12 \pmod {82} $$ This is how far I got: $$ 8x \equiv 3 \: \left( \mathrm{mod} \: \frac{82}{\mathrm{GCD}(82, 4)} \right) $$ $$ \Updownarrow $$ $$ 8x \equiv 3 \pmod {41} $$

What could I do next? Please provide solutions without the Euclidean algorithm.


What I found later is that I can say that $$ 0 \equiv 205 \pmod {41} $$ And then I can add it to the congruence in question and divide by $8$. So I guess my question is essentially 'How can I find a number that is a multiple of $41$ (the modulus) and which, if added to $3$ gives a number that is divisible by $8$?'

I reckon the Euclidean algorithm is something which gives an answer to these kinds of questions?!

  • 4
    $\begingroup$ It's just too bad that the Euclidean algorithm is the perfect way to tackle these problems. $\endgroup$ – Lord Shark the Unknown Sep 9 '17 at 11:28
  • $\begingroup$ I'd suggest turning it into algebraic equations without congruence. $\endgroup$ – user451844 Sep 9 '17 at 11:30
  • $\begingroup$ @LordSharktheUnknown I am aware of that, but as I am a complete beginner in the topic, I'd firstly like to find solutions which do not involve the algorithm which I am not familiar with yet. $\endgroup$ – bertalanp99 Sep 9 '17 at 11:37
  • 1
    $\begingroup$ In that case you may just observe that as $\gcd(5,41)=1$ $$8x\equiv3\pmod{41}\Leftrightarrow40x\equiv15\pmod{41}.$$ Here $40\equiv-1$, so... This amounts to replacing Extented Euclidean Algorithm with a "lucky" observation. $\endgroup$ – Jyrki Lahtonen Sep 9 '17 at 11:39
  • $\begingroup$ Please see my edit $\endgroup$ – bertalanp99 Sep 9 '17 at 11:40

Hint :you can do like this $$\quad{8x \equiv 3 \pmod {41}\\ 8x \equiv 3+41 \pmod {41}\\8x \equiv 44 \pmod {41} \div4 \\ 2x \equiv 11 \pmod {41}\\2x \equiv 11+41 \pmod {41}\\2x \equiv 52 \pmod {41}\div 2\\x \equiv 26 \pmod {41}\\x=41q+26}$$


You just have to find the inverse of $8$ modulo $41$.

The general method uses the extended Euclidean algorithm, but in the particular case, it's much simpler: from $5\cdot 8=40\equiv -1\mod 41$, you get at once that $8^{-1}\equiv -5\mod 41$, so $$x\equiv -5\cdot 3=-15\equiv 26\mod 41.$$


basically you are asking how to solve $\frac 1n \mod m$ where $\gcd(m,n)=1$

where $\frac 1n \mod m$ is notation for the $x$ so that $n*x \equiv 1\mod m$.

Let $m = k + qn$ then $nx = 1 + Zm = 1 + Z(k + qn)$ implies

$x = \frac 1n + \frac {Zk}n + Zq$ where $n|Zk + 1$

Ex. $x \equiv \frac 17 \mod 67$. As $67 = 9*7 + 4$ then

$x = \frac {1+Z*4}{7} + 9$

Which means we have to find $Z \equiv -\frac 14 \mod 7$.

Oh... I guess this is Euclid's algorithm.

$7 = 3 + 4$

So $-Z = \frac{1+ 3Y}4 + 1$

Which is clearly $Y =1$ and $-Z \equiv 2\mod 7$ and $Z \equiv -2 \mod 7$

and $x = \frac {1 + 4*(-2)}7 + (-2)*9 \equiv -19 \mod 67$.

And indeed $7*(-19) \equiv -133= (-1)*67 + 1 \equiv 1 \mod 67$

... Yeah, you need Euclid's alogrithm.


OK, without the Euclidean algorithm, you are looking for some $k$ such that $8$ divides $41k+3$, which gives you a new equation in smaller numbers (which is a Euclidean algorithm idea too, but still): $$41k+3\equiv 0 \bmod 8 \\ 41\equiv 1 \bmod 8 \\ k+3 \equiv 0 \bmod 8 \\ k\equiv 5 \bmod 8$$

So then you have your $41\times 5 = 205$ to make the divisibility.


$\, 8x = 3\!+\!41n\!\iff\!\bmod 8\!:\ 0\equiv 3\!+\!41n\equiv 3\!+\!n\!\iff\! n\equiv -3\,$ so $\,x\equiv \frac{3+41(-3))}8\equiv -15\equiv 26$

Alternatively $\bmod 41\!:\ x\equiv \dfrac{3}{8}\equiv \dfrac{15}{40}\equiv\dfrac{15}{-1}\equiv 26\ $ by Gauss's algorithm

Alternatively $ \bmod 41\!:\ x\equiv \dfrac{3}{8}\equiv \dfrac{44}{8}\equiv \dfrac{11}{2}\equiv\dfrac{52}{2}\equiv 26\ $ by adding $\pm 41$ to simplify divisions

Alternatively $\bmod 41\!:\ x\equiv \dfrac{1}8\,\dfrac{3}1\equiv \dfrac{-40}8\ \dfrac{3}1\equiv (-5)3\equiv -15$

Remark $ $ The first method essentially uses a single step of the (extended) Euclidean algorithm, and the second is a special case of that for prime moduli. The other methods are ad-hoc - they try to massage the fractions by adding small multiples of the modulus to make quotients exact / simpler.

Beware $\ $ Modular fraction arithmetic is well-defined only for fractions with denominator coprime to the modulus. See here for further discussion.


$$ 32x\equiv12\pmod{82} $$ is equivalent to $$ 16x\equiv6\pmod{41} $$ and since $(41,2)=1$, we can divide by $2$ $$ 8x\equiv3\pmod{41} $$ Then noting that $5\cdot8\equiv-1\pmod{41}$, we get that $36\cdot8\equiv1\pmod{41}$. Multiplying both sides by $36$ yields $$ \bbox[5px,border:2px solid #C0A000]{x\equiv26\pmod{41}} $$ Note: When looking for the inverse of $a$ mod $m$ it is often a good idea to see if $a\mid(m-1)$ or $a\mid(m+1)$; if either of these hold, they give a quick inverse mod $m$: $a^{-1}\equiv-\frac{m-1}a$ or $a^{-1}\equiv\frac{m+1}{a}$. Above, it was noted that $8|(41-1)$ leading to $8^{-1}\equiv-\frac{41-1}8\pmod{41}$.

Alternate Method of Finding the Inverse of $\boldsymbol{8\pmod{41}}$

Since $41$ is prime and $(41,8)=1$, we know, by Fermat's Little Theorem, that $8^{39}\equiv8^{-1}\pmod{41}$. We can compute $8^{39}\pmod{41}$ using the Square and Multiply Algorithm. $39=100111_\text{two}$, therefore, $$ \begin{align} 8^1&\equiv8&\pmod{41}\\ 8^2&\equiv23&\pmod{41}&&\text{square}\\ 8^4&\equiv37&\pmod{41}&&\text{square}\\ 8^8&\equiv16&\pmod{41}&&\text{square}\\ 8^9&\equiv5&\pmod{41}&&\text{multiply}\\ 8^{18}&\equiv25&\pmod{41}&&\text{square}\\ 8^{19}&\equiv36&\pmod{41}&&\text{multiply}\\ 8^{38}&\equiv25&\pmod{41}&&\text{square}\\ 8^{39}&\equiv36&\pmod{41}&&\text{multiply}\\ \end{align} $$ Therefore, $8^{-1}\equiv36\pmod{41}$.

  • $\begingroup$ You should elaborate on how you "note that $5\cdot 8\equiv -1$" else it amounts to pulling the inverse out of a hit - which is good for magic, but not for math. $\endgroup$ – Bill Dubuque Sep 10 '17 at 18:33
  • $\begingroup$ @BillDubuque: Is it magic to realize that $5\cdot8=40$? Be careful when casting stones. This is why I added the second method. $\endgroup$ – robjohn Sep 10 '17 at 18:41
  • $\begingroup$ If you don't say how you "note" that then it is magic, not math. There are of course many ways to compute such inverses, so it is strange that you want to exhibit the inverse but not say how you computed it. Helping someone improve an answer is certainly not "casting stones". In case you may not have noticed, I often give constructive feedback on answers where results are pulled out of a hat. $\endgroup$ – Bill Dubuque Sep 10 '17 at 19:17
  • $\begingroup$ Certainly, in general, I would not suggest an answer by inspection, however, in this answer you seem to suggest that inspection is a valid approach. However, since I knew that was not a good general strategy, I supplied the alternate, non-Euclidean Algorithm, approach. Furthermore, I have added a description of how I came up with $5\cdot8\equiv-1\pmod{41}$, but as this doesn't work in general, I originally opted to describe the Fermat's Little Theorem approach. $\endgroup$ – robjohn Sep 10 '17 at 22:12
  • $\begingroup$ Inspection (or brute-force) is much easier there being mod $3$ vs. mod $41$ (and there I say by "inspection or Euclid"). Glad to see that you added an explanation. I call this method the easy inverse case, It is equivalent to the numerator twiddling I do with fractions in my answer, i.e. try $\ 1/a\equiv (1\pm km)/a\pmod{\!m}\,$ for small $k$ to try to make the division exact (i.e. try the first few steps of a brute-force search). It often proves handy for greatly simplifying CRT calculations. $\endgroup$ – Bill Dubuque Sep 10 '17 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.