Congruences and Linear Congruences
Congruence means — two integers leave the same remainder when divided by . A linear congruence is solvable iff , in which case it has exactly solutions modulo . Used throughout number theory, cryptography, and computer arithmetic. Concept formalized by Gauss in Disquisitiones Arithmeticae (1801).A congruence is an equivalence relation on the integers that partitions into residue classes according to remainder upon division by a fixed modulus . Linear congruences are the modular analogue of linear equations , and their solution theory is the gateway to the Chinese Remainder Theorem, modular inverses, and public-key cryptography. The subject matters because it transforms infinitely many integer problems into finite arithmetic on the ring , where computation is tractable. A surprising fact: a single linear congruence can have zero, one, or several incongruent solutions — unlike the real line, where with always has exactly one — and the count is governed entirely by a greatest common divisor.
The Core Insight
Divisibility by is an equivalence relation that respects addition and multiplication. This lets us "compute modulo " inside a finite ring. Solving then reduces to a divisibility test () plus the Extended Euclidean Algorithm, which simultaneously certifies solvability and produces the solution.
Formal Statement
Congruence Modulo m
Let be a positive integer. Integers and are congruent modulo , written , if divides their difference:
Here , is the modulus, and is the integer quotient of the difference. Equivalently, and have the same remainder under Euclidean division by .
Residue Class and the Ring $\mathbb{Z}/m\mathbb{Z}$
The residue class of modulo is the set
There are exactly distinct residue classes , forming the quotient ring under the well-defined operations and .
Congruence is a Compatible Equivalence Relation
For fixed , congruence mod is reflexive, symmetric, and transitive, and is preserved by addition, subtraction, and multiplication: if and , then
Linear Congruence
A linear congruence in the unknown is
A solution is any integer satisfying [4]; solutions come in entire residue classes, so we count solutions modulo (incongruent solutions).
Solvability and Solution Count
Let . The congruence has a solution iff . When solvable, it has exactly incongruent solutions modulo . If is any one solution, all solutions are
Why It Holds / Derivation
Solvability and Count
Step 1 — Reformulate as a Bézout problem. By [1], means , i.e. there exists with , equivalently the linear Diophantine equationCancellation and Modular Inverse
If , then (cancellation is valid). More generally,
Consequently has a multiplicative inverse modulo iff , satisfying
Residue classes mod 5 wrapping the number line onto a circle, and the orbit of multiplication by 2
Building Intuition
intuition Think of a clock with hours. Adding always wraps around, so behaves like a finite circular ruler. Solving asks: "starting at and stepping by each time, do I ever land exactly on ?" The reachable points are precisely the multiples of on the dial. If is one of them, you can land there in symmetric ways; if it is not, you never can. This is why the gcd — not the magnitude of — controls everything.
Carl Friedrich Gauss | 1777–1855
Gauss introduced the notation and the very word "congruence" in Disquisitiones Arithmeticae (1801), written when he was in his early twenties. By treating like , he revealed that the integers carry a rich algebraic structure under divisibility, unifying scattered results of Fermat, Euler, and Lagrange. His systematic theory of congruences — including quadratic reciprocity, proved in the same work — founded modern number theory and made the modulus a first-class object of computation.
Worked Examples
A Congruence with a Unique Solution
Solve . Given: .- Compute . Since , a solution exists, and it is unique mod .
- Find via Extended Euclid: , so .
- Multiply: .
- Check: . ✓
A Congruence with Several Solutions
Solve . Given: .- . Since , the congruence is solvable with exactly incongruent solutions mod .
- Divide through by : .
- Solve the reduced congruence: (since ), so . Take .
- Lift using [5] with : .
- Check : . ✓
Common Misconceptions
You cannot always cancel a common factor. From ... harmless, but from you may not conclude — it happens to be false (). Cancellation of is legal only when ; otherwise the modulus must shrink to as in [6]. A second frequent error is treating as if it always has a unique solution like a real equation; the solution count is , which may be (no solutions) or larger than .Consider . Here but , so no solution exists. Indeed is always even, hence and can never equal . This shows the criterion is genuinely necessary: an innocent-looking linear congruence can be outright unsolvable.
Connections
Congruences are the foundation of Modular Arithmetic and the ring structure of Quotient Rings: is the prototypical quotient. Systems of simultaneous congruences with coprime moduli are solved by the Chinese Remainder Theorem, which reassembles the ring as a product . The invertibility criterion identifies the Units in Modular Arithmetic, whose count is Euler's Totient Function , and whose order theory yields Fermat's Little Theorem and Euler's Theorem. The constructive engine throughout is the Extended Euclidean Algorithm.
Real-World Applications
- RSA cryptography — encryption and decryption are the modular exponentiations and , with key generation solving , a linear congruence.
- Hash tables and checksums — index ; ISBN-10, IBAN, and UPC use congruence-based check digits to detect transcription errors.
- Pseudorandom number generators — linear congruential generators iterate .
- Calendar algorithms — Zeller's congruence computes the day of week via arithmetic mod 7.
- Diffie–Hellman key exchange — security rests on the discrete logarithm in .
- Error-correcting codes — Reed–Solomon and CRC codes compute remainders modulo a generator polynomial, the polynomial analogue of these congruences.
- Cryptographic timing / clock synchronization — counters and rollover are managed with fixed-modulus arithmetic.
Historical Development
- 3rd c. CE — Sun Tzu's Sunzi Suanjing poses the first recorded simultaneous-congruence problem (counting an unknown by remainders), seeding the Chinese Remainder Theorem.
- 1247 — Qin Jiushao gives a general procedure (Dayan rule) for solving simultaneous congruences with non-coprime moduli.
- 1640 — Fermat states his little theorem in correspondence.
- 1736 — Euler publishes the first proof of Fermat's little theorem and later generalizes it via .
- 1801 — Gauss's Disquisitiones Arithmeticae introduces the notation, the term "congruence," and the systematic theory of linear and quadratic congruences.
- 1832 — Gauss extends congruences to Gaussian integers, broadening the modulus concept beyond .
- 1801–1900s — Dirichlet, Dedekind, and Kronecker recast congruences as ideal-theoretic statements, birthing the ring and modern algebra.
- 1949 — D. H. Lehmer formalizes the linear congruential generator for computing.
- 1977 — Rivest, Shamir, and Adleman base RSA on linear and exponential congruences, turning the theory into critical infrastructure.
Subtleties & Limits
While linear congruences are completely solved by the gcd criterion, their nonlinear cousins remain deep. Solving is trivial, but solving the discrete logarithm has no known efficient classical algorithm and underlies modern cryptography; Shor's quantum algorithm solves it in polynomial time, so its real-world hardness is conditional. Likewise, counting or finding solutions to general polynomial congruences mod composite is intimately tied to integer factorization. Even the distribution of solutions of as vary feeds open questions in analytic number theory about equidistribution of residues and the spacing of modular inverses (the Lehmer problem on of ).