Solvability is a divisibility test
g = gcd(a,m) must divide b. That check is one gcd computation and it settles the question.
The modular analogue of a linear equation. It has either no solutions or exactly gcd(a,m) of them, and which case you are in is decided before any work is done.
Core ideas
Unlike a linear equation over the reals, this can have no solutions or many — and the gcd decides which.
g = gcd(a,m) must divide b. That check is one gcd computation and it settles the question.
Not one, and not m. The solutions form one class modulo m/g, which splits into g classes modulo m.
gcd(a,m) = 1 gives a unique solution x ≡ a⁻¹b, computed by the extended algorithm of “Bézout's Identity and Modular Inverses”.
The material
The criterion, the count, and the method.
Let g = gcd(a, m). The congruence ax ≡ b (mod m) has a solution if and only if g | b, and in that case it has exactly g solutions modulo m.
ax ≡ b (mod m) means ax − my = b for some integer y. By Bézout the set of values ax − my is exactly the multiples of g, so a solution exists precisely when g | b.
Suppose g | b and divide through: (a/g)x ≡ (b/g) (mod m/g). Now gcd(a/g, m/g) = 1, so this reduced congruence has a unique solution x₀ modulo m/g.
Lifting back, the solutions modulo m are x₀, x₀ + m/g, x₀ + 2m/g, …, x₀ + (g−1)m/g — exactly g of them.
□
6x ≡ 7 (mod 15). gcd(6,15) = 3 and 3 ∤ 7, so there is no solution at all. Note that this is decided in one line, before any attempt to solve.
6x ≡ 9 (mod 15). gcd(6,15) = 3 and 3 | 9, so three solutions exist. Divide through: 2x ≡ 3 (mod 5), and since 2⁻¹ ≡ 3 (mod 5), x ≡ 9 ≡ 4 (mod 5). Lifting: x ≡ 4, 9, 14 (mod 15). Check: 6·4 = 24 ≡ 9, 6·9 = 54 ≡ 9, 6·14 = 84 ≡ 9. All three work.
7x ≡ 3 (mod 26). gcd(7,26) = 1, so exactly one solution. The inverse of 7 mod 26 is 15, since 7 · 15 = 105 = 4·26 + 1. So x ≡ 45 ≡ 19 (mod 26).
The reduced congruence lives modulo m/g and has one solution there. Each class modulo m/g contains exactly g classes modulo m, so one solution downstairs becomes g upstairs. Answering "one" or "m" both miss this, and the count matters for the systems of “The Chinese Remainder Theorem”.
That is the structural explanation. Over a field every nonzero coefficient can be divided out; modulo a composite m it cannot, and the failure is measured exactly by the gcd.
Interactive
Algorithms with their traces
Method
Compute the gcd first; it answers most of the question.
One run of Euclid. If g ∤ b, there is no solution and you are finished.
All three of a, b and the modulus. The reduced coefficient is now coprime to the reduced modulus.
x ≡ (a/g)⁻¹(b/g) (mod m/g), using the extended algorithm of “Bézout's Identity and Modular Inverses”.
Add multiples of m/g to produce all g solutions modulo m, and check at least one by substitution.
A case with several solutions, worked in full.
Both checks were worth doing: the lift is the step where a solution is most often lost. Reporting only x ≡ 45 would be half an answer, and reporting x ≡ 45 (mod 50) would be a correct statement about the wrong modulus.
Solve 15x ≡ 25 (mod 35), stating the number of solutions before finding any. gcd(15,35) = 5 divides 25, so there are five, spaced 7 apart.
Something to change about this lesson? Write it down, tick it off when it is handled, and export the list when you want to act on it. Kept in this browser only: nothing is sent anywhere, and nobody is notified.
No recommendations yet for this lesson.