SECTION 1
Historical Context & Motivation
The study of linear congruences is among the oldest problems in number theory, arising naturally whenever one asks about divisibility patterns and remainders. Ancient civilizations recognized that certain arithmetic problems—distributing objects into equal groups, scheduling recurring events, or solving puzzles about unknown quantities—reduce to questions about residues modulo an integer. The formal language of congruences, however, took centuries to develop, and its codification transformed number theory from a collection of clever tricks into a rigorous algebraic discipline. Today, solving equations of the form ax ≡ b (mod m) is a gateway skill for understanding modular arithmetic and its profound applications in cryptography, coding theory, and computer science.
~300 CE • Sun Zi's Remainder Problem
628 • Brahmagupta's Kuttaka Method
1801 • Gauss's Disquisitiones Arithmeticae
1977 • RSA Cryptosystem
The central question that linear congruences address is deceptively simple: given integers a, b, and m, can we find an integer x such that ax leaves remainder b upon division by m? Under what conditions does a solution exist, and when it does, how many solutions are there modulo m? These questions lead directly to the concept of modular inverses and the role of the greatest common divisor as the arbiter of solvability.
SECTION 2
Core Principles & Definitions
Before solving linear congruences, we need to establish the precise definitions and foundational results that govern their behavior. A congruence a ≡ b (mod m) asserts that m divides the difference a − b, or equivalently, that a and b share the same remainder when divided by m. A linear congruence is an equation of the form ax ≡ b (mod m), where a, b, m are given integers with m > 0, and x is the unknown. The following principles form the backbone of the theory.
Congruence as Equivalence
Existence Theorem
Number of Solutions
Modular Inverse
Extended Euclidean Algorithm
KEY TAKEAWAY
SECTION 3
Visual Explanation
The following diagram illustrates how the residues of multiples of a behave modulo m, depicting the 'stepping around a clock' metaphor. We visualize ℤ/mℤ as a circular arrangement of m positions and trace where successive multiples of a land, revealing the connection between gcd(a, m) and reachability.
The diagram above makes the existence theorem visually immediate. On the left, with a = 3 and m = 9, the multiples of 3 modulo 9 cycle through only {0, 3, 6}, covering exactly 9/gcd(3,9) = 3 distinct residues. Consequently, 3x ≡ b (mod 9) is solvable only when b ∈ {0, 3, 6}—precisely the multiples of d = 3. On the right, with a = 5 and m = 9, the gcd is 1, so stepping by 5 visits every residue class before returning to the start. This is why coprimality of a and m guarantees not merely existence but uniqueness of the solution modulo m. Understanding this geometric picture provides strong intuition for why the Extended Euclidean Algorithm works: it is essentially constructing the precise sequence of steps needed to reach any given target on the circle.
SECTION 4
Mathematical Framework
We now formalize the theory. The fundamental objects are the linear congruence equation and the conditions that govern its solution set. Throughout, we let a, b, m ∈ ℤ with m > 0.
LINEAR CONGRUENCE
This states that m | (ax − b), or equivalently, there exists an integer k such that ax = b + km. The unknowns are x ∈ ℤ.
EXISTENCE CONDITION
Let d = gcd(a, m). The congruence is equivalent to the Diophantine equation ax − my = b, which by Bézout's identity has integer solutions if and only if d divides b.
SOLUTION COUNT
If x₀ is one solution, the complete solution set is x ≡ x₀ + k(m/d) (mod m) for k = 0, 1, …, d−1. When d = 1, there is exactly one solution modulo m.
REDUCTION TO COPRIME CASE
When d > 1 and d | b, divide every coefficient by d. The reduced congruence has gcd(a/d, m/d) = 1, so the modular inverse of a/d modulo m/d exists and yields the unique base solution x₀ modulo m/d.
Connection to Bézout's Identity
SECTION 5
Solution Algorithm & Classification
With the theory established, we can organize the solution procedure into a systematic algorithm. The flowchart below captures the decision logic, while the subsequent table classifies the different scenarios one may encounter when solving a linear congruence.
| Scenario | Condition | # Solutions (mod m) | Example |
|---|---|---|---|
| No solution | gcd(a, m) ∤ b | 0 | 4x ≡ 3 (mod 6): gcd(4,6) = 2 ∤ 3 |
| Unique solution | gcd(a, m) = 1 | 1 | 3x ≡ 5 (mod 7): gcd(3,7) = 1 |
| Multiple solutions | d = gcd(a,m) > 1 and d | b | d | 6x ≡ 4 (mod 8): gcd(6,8) = 2 | 4 → 2 soln's |
| Trivial (a ≡ 0) | a ≡ 0 (mod m), b ≡ 0 (mod m) | m (every residue) | 0x ≡ 0 (mod 5): every x works |
Classification of solution scenarios for ax ≡ b (mod m)
SECTION 6
Worked Example
Let us solve the congruence 12x ≡ 18 (mod 30) step by step, demonstrating every stage of the algorithm including the Extended Euclidean computation.
Solve 12x ≡ 18 (mod 30)
- 1
Step 1 — Compute gcd(a, m)
Apply the Euclidean Algorithm to a = 12 and m = 30. We have 30 = 2 × 12 + 6, then 12 = 2 × 6 + 0. Therefore gcd(12, 30) = 6.d = gcd(12, 30) = 6 - 2
Step 2 — Check existence condition
We need d | b, i.e., 6 | 18. Since 18 = 3 × 6, the condition is satisfied. A solution exists, and there will be exactly d = 6 incongruent solutions modulo 30.6 | 18 ✓ — solutions exist - 3
Step 3 — Reduce to coprime case
Divide every coefficient by d = 6: a/d = 12/6 = 2, b/d = 18/6 = 3, m/d = 30/6 = 5. The reduced congruence is 2x ≡ 3 (mod 5). Note that gcd(2, 5) = 1, confirming the coprime condition.Reduced: 2x ≡ 3 (mod 5) - 4
Step 4 — Find modular inverse of a/d mod m/d
We need 2⁻¹ mod 5. Apply the Extended Euclidean Algorithm: 5 = 2 × 2 + 1, so 1 = 5 − 2 × 2, giving s = −2. Reducing modulo 5: −2 ≡ 3 (mod 5). Verify: 2 × 3 = 6 ≡ 1 (mod 5). ✓2⁻¹ ≡ 3 (mod 5) - 5
Step 5 — Compute base solution
Multiply both sides of 2x ≡ 3 (mod 5) by 2⁻¹ = 3: x ≡ 3 × 3 (mod 5) = 9 ≡ 4 (mod 5). The base solution is x₀ = 4.x₀ ≡ 4 (mod 5) - 6
Step 6 — Enumerate all solutions modulo m
The d = 6 solutions modulo 30 are x ≡ x₀ + k(m/d) (mod m) = 4 + 5k (mod 30) for k = 0, 1, 2, 3, 4, 5. Computing: x ∈ {4, 9, 14, 19, 24, 29}. Each can be verified: 12 × 4 = 48 ≡ 18 (mod 30) ✓, 12 × 9 = 108 ≡ 18 (mod 30) ✓, and so on.x ≡ 4, 9, 14, 19, 24, 29 (mod 30)
Verification Tip
SECTION 7
Solution Methods Compared
While the Extended Euclidean Algorithm is the general-purpose tool for solving linear congruences, several alternative approaches exist. Each has its own strengths and appropriate contexts. The following comparison helps you choose the right method for a given situation.
| Method | Strengths | Limitations |
|---|---|---|
| Brute-force search | Trivial to implement; no theory needed; guarantees finding all solutions for small moduli | O(m) time complexity; completely impractical for large m (e.g., cryptographic sizes ~ 10³⁰⁰) |
| Extended Euclidean Algorithm | O(log m) time; handles all cases including d > 1; directly produces Bézout coefficients | Multi-step bookkeeping; negative intermediate values require careful sign handling |
| Euler's theorem () | Elegant theoretical connection; useful when φ(m) is easily computed (e.g., m prime) | Requires gcd(a,m) = 1; computing φ(m) for large composite m requires factorization |
| Inspection / mental arithmetic | Fastest for small moduli (m ≤ 20); builds number sense and intuition | Not systematic; error-prone; does not scale |
Comparison of methods for solving ax ≡ b (mod m)
PRACTICAL ADVICE
pow(a, -1, m) (Python 3.8+), which internally uses exactly this algorithm.SECTION 8
Connections to Advanced Topics
Linear congruences are the simplest equations in modular arithmetic, but they serve as the launching pad for a rich landscape of more advanced results. The table below maps how each idea generalizes, illustrating that mastering the introductory case provides essential scaffolding for the rest of number theory and its applications.
| Introductory Concept | Advanced Generalization | Application Domain |
|---|---|---|
| Single linear congruence ax ≡ b (mod m) | Systems of simultaneous congruences → Chinese Remainder Theorem | Fault-tolerant computing, secret sharing |
| Modular inverse a⁻¹ mod m | Multiplicative group (ℤ/mℤ)* and Euler's theorem | RSA key generation, Diffie-Hellman |
| Extended Euclidean Algorithm | Continued fractions, lattice basis reduction | Cryptanalysis, integer programming |
| Linear congruence in one variable | Polynomial congruences and Hensel's lemma | p-adic analysis, algebraic number theory |
| Existence via gcd condition | Solvability in rings, ideal theory | Abstract algebra, algebraic geometry |
From introductory linear congruences to advanced mathematics
Perhaps the most immediate next step is the Chinese Remainder Theorem (CRT), which addresses systems of linear congruences with pairwise coprime moduli. Given the system x ≡ a₁ (mod m₁), x ≡ a₂ (mod m₂), …, x ≡ aₖ (mod mₖ), the CRT guarantees a unique solution modulo m₁m₂···mₖ. Each individual congruence in the CRT construction is solved using exactly the techniques covered in this lesson. Beyond the CRT, polynomial congruences like x² ≡ a (mod p) (quadratic residues) and higher-degree congruences build on the linear case through iterative lifting procedures such as Hensel's lemma.
SECTION 9
Practice Problems
Question 1: CONCEPTUAL
Show answer
Question 2: BASIC CALCULATION
Show answer
Question 3: INTERMEDIATE
Show answer
Question 4: APPLIED
Show answer
Question 5: CRITICAL THINKING
Show answer
SUMMARY
Summary & Review
Summary
A linear congruence ax ≡ b (mod m) asks for integers x whose product with a leaves remainder b upon division by m. The existence theorem states that solutions exist if and only if d = gcd(a, m) divides b, and when they do, there are exactly d incongruent solutions modulo m. The solution procedure involves dividing through by d to obtain a coprime reduced congruence, finding the modular inverse of a/d modulo m/d via the Extended Euclidean Algorithm, and then generating all solutions by adding multiples of m/d.
This technique is the entry point to a vast array of applications: from the Chinese Remainder Theorem for systems of congruences, to RSA cryptography where computing modular inverses is the central operation in key generation. Mastering the interplay between divisibility, residue classes, and modular arithmetic provides essential algebraic fluency for all subsequent work in number theory and discrete mathematics.