Maths WorkshopMaths problems with full solutions
Exercise 851Number theory › CongruencesL1Added 3 Nov 2026

Solvability of $ax\equiv b\pmod n$

#linear congruence#gcd criterion#number of solutions

Statement

Show that ax≡b(modn)ax\equiv b\pmod n has solutions iff gcd⁡(a,n)∣b\gcd(a,n)\mid b, and in that case has exactly gcd⁡(a,n)\gcd(a,n) solutions modulo nn.

Hint

Let d=gcd⁡(a,n)d=\gcd(a,n). Reduce to the coprime case by dividing by dd.

Show solutionHide solution

Solution

Necessity. If ax≡b(modn)ax\equiv b\pmod n, then ax−b=knax-b=kn, so d∣ax−knd\mid ax-kn, hence d∣bd\mid b.

Sufficiency. Suppose d∣bd\mid b, say b=db′b=db'. Write a=da′a=da', n=dn′n=dn'. Then a′x≡b′(modn′)a'x\equiv b'\pmod{n'} with gcd⁡(a′,n′)=1\gcd(a',n')=1. Since a′a' is invertible mod n′n', there is a unique solution x≡x0(modn′)x\equiv x_0\pmod{n'}.

Lifting. The solutions mod nn are x0,x0+n′,x0+2n′,…,x0+(d−1)n′x_0, x_0+n', x_0+2n',\ldots,x_0+(d-1)n': exactly dd solutions.

Conclusion. ax≡b(modn)ax\equiv b\pmod n has d=gcd⁡(a,n)d=\gcd(a,n) solutions mod nn iff d∣bd\mid b.