Chinese Remainder Theorem Calculator

Solve systems of simultaneous congruences x ≡ a₁ (mod m₁), x ≡ a₂ (mod m₂), … using CRT. Handles 2 or 3 congruences, coprimality checks, step-by-step Bézout construction, and historical context.

x ≡ ? (mod M)
M = m₁ × m₂
Moduli coprime?
Extended More scenarios, charts & detailed breakdown
Solution x mod M
Step-by-step
Professional Full parameters & maximum detail

Solution

CRT Solution
Explicit Formula

Context

Historical Note
Applications

How to Use This Calculator

  1. Enter remainders a₁, a₂ and moduli m₁, m₂. The unique solution x mod M appears instantly.
  2. Use 3 Congruences tab for three simultaneous equations.
  3. Use Coprimality Check to verify moduli are pairwise coprime before solving.
  4. Use Professional to see the explicit formula with Bézout coefficients.

Formula

x = Σ aᵢ × Mᵢ × yᵢ (mod M) where M=Πmᵢ, Mᵢ=M/mᵢ, yᵢ=Mᵢ⁻¹ mod mᵢ

Example

x≡2(mod 3), x≡3(mod 5): M=15, y₁=2, y₂=2 → x=(2×5×2+3×3×2) mod 15=38 mod 15=8. Check: 8 mod 3=2 ✓, 8 mod 5=3 ✓

Frequently Asked Questions

  • The Chinese Remainder Theorem (CRT) states that if moduli m₁, m₂, …, mₖ are pairwise coprime (every pair shares no common factor), then for any choice of remainders a₁, a₂, …, aₖ there exists a unique solution x modulo M = m₁ × m₂ × … × mₖ satisfying all congruences simultaneously: x ≡ a₁ (mod m₁), x ≡ a₂ (mod m₂), etc. The solution is unique within [0, M). This theorem transforms a system of congruences into a single congruence, which is powerful for large-number arithmetic.
  • "Pairwise coprime" means every pair of moduli shares no common factor other than 1: gcd(mᵢ, mⱼ) = 1 for all pairs i ≠ j. Example of pairwise coprime moduli: 3, 5, 7 — each pair (3,5), (3,7), (5,7) has GCD = 1. Non-example: 4, 6, 15 — gcd(4,6) = 2 ≠ 1, so they are not pairwise coprime. The pairwise coprime condition is required by the basic CRT. If moduli are not coprime, a generalized CRT handles some cases, but the system may have no solution or infinitely many.
  • Step 1: M = 3 × 5 = 15. Step 2: M₁ = M/m₁ = 5, M₂ = M/m₂ = 3. Step 3: find y₁ = M₁⁻¹ mod m₁ = 5⁻¹ mod 3 = 2 (since 5×2=10≡1 mod 3). Find y₂ = M₂⁻¹ mod m₂ = 3⁻¹ mod 5 = 2 (since 3×2=6≡1 mod 5). Step 4: x = a₁M₁y₁ + a₂M₂y₂ = 2×5×2 + 3×3×2 = 20 + 18 = 38 ≡ 38 mod 15 = 8. Verify: 8 mod 3 = 2 ✓, 8 mod 5 = 3 ✓. The unique solution is x = 8 (mod 15).
  • If two moduli share a common factor, the basic CRT does not apply. The system x ≡ a₁ (mod m₁), x ≡ a₂ (mod m₂) with gcd(m₁,m₂) = d may have no solution (if d does not divide a₁ − a₂) or infinitely many solutions modulo lcm(m₁,m₂) (if d divides a₁ − a₂). For example, x ≡ 1 (mod 4) and x ≡ 3 (mod 6): gcd=2, a₁−a₂=−2, which 2 divides, so solutions exist: x ≡ 9 (mod 12). This calculator checks coprimality automatically and reports when the basic CRT cannot proceed.
  • CRT has several important applications: RSA-CRT decryption decomposes a large modular exponentiation into two smaller ones (mod p and mod q), speeding up RSA by about 4×. Calendar cycles: "what day of the week falls on a given date?" uses modular arithmetic with moduli 7, 30, 365. Error-correcting codes in communications use CRT for efficient recovery from errors. Computer arithmetic: representing large integers using several small moduli (Residue Number System) enables fast parallel computation. Secret sharing (Mignotte threshold schemes) uses CRT to split secrets.

Related Calculators

Sources & References (5)
  1. Sun Tzu Suan Ching (Mathematical Classic) — 5th century — Historical Primary Source
  2. An Introduction to the Theory of Numbers — Niven, Zuckerman & Montgomery — Wiley
  3. Chinese Remainder Theorem — Wolfram MathWorld — Wolfram Research
  4. NIST DLMF — §27.5 Congruences — NIST
  5. An Introduction to the Theory of Numbers — Hardy & Wright — Oxford University Press