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:

1
⟳" divides " means for some integer ; apply directly to .

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

2
⟳collect all integers congruent to ; by [1] they differ from by a multiple of .

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

3
⟳write , ; then and , both multiples of .

Linear Congruence

A linear congruence in the unknown is

4
⟳replace the equality in the linear equation by congruence mod .

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

5
⟳divide through by to get with and , which has a unique solution mod ; lift back to to get classes spaced apart.

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 equation
Step 2 — Apply Bézout's identity. This Diophantine equation in is solvable iff . Set . If there is no solution; this proves the solvability criterion. Step 3 — Reduce to a coprime modulus. Assume and write , , with . Dividing by yields
Step 4 — Unique solution mod . Since , is invertible in (see [7] below). Multiplying by gives a unique . Step 5 — Lift to and count. A residue class mod splits into residue classes mod , namely . These are exactly the incongruent solutions in [5].

Cancellation and Modular Inverse

If , then (cancellation is valid). More generally,

6
⟳; remove the common factor from and , leaving since the reduced cofactor of is coprime to it.

Consequently has a multiplicative inverse modulo iff , satisfying

7
⟳Bézout gives integers with ; reducing mod gives , so .

Residue classes mod 5 wrapping the number line onto a circle, and the orbit of multiplication by 2

Integers mod 5 as a clock 0 1 2 3 4 …,-5,0,5,10,… all map to class 0 ×2 orbit: 1→2→4→3→1

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: .
  1. Compute . Since , a solution exists, and it is unique mod .
  2. Find via Extended Euclid: , so .
  3. Multiply: .
  4. Check: . ✓

A Congruence with Several Solutions

Solve . Given: .
  1. . Since , the congruence is solvable with exactly incongruent solutions mod .
  2. Divide through by : .
  3. Solve the reduced congruence: (since ), so . Take .
  4. Lift using [5] with : .
  5. 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

  1. RSA cryptography — encryption and decryption are the modular exponentiations and , with key generation solving , a linear congruence.
  2. Hash tables and checksums — index ; ISBN-10, IBAN, and UPC use congruence-based check digits to detect transcription errors.
  3. Pseudorandom number generators — linear congruential generators iterate .
  4. Calendar algorithms — Zeller's congruence computes the day of week via arithmetic mod 7.
  5. Diffie–Hellman key exchange — security rests on the discrete logarithm in .
  6. Error-correcting codes — Reed–Solomon and CRC codes compute remainders modulo a generator polynomial, the polynomial analogue of these congruences.
  7. 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 ).

See Also

Modular Arithmetic · Chinese Remainder Theorem · Extended Euclidean Algorithm · Euler's Totient Function · Fermat's Little Theorem · Quadratic Reciprocity · Quotient Rings · Discrete Logarithm

Before this

Where this leads