Chinese Remainder Theorem Calculator
Solve systems of modular congruences using the Chinese Remainder Theorem. Computes unique solutions with step-by-step Extended Euclidean Algorithm.
About
The Chinese Remainder Theorem (CRT) guarantees a unique solution modulo M = m1 ⋅ m2 ⋅ … ⋅ mk for a system of simultaneous congruences x ≡ ai (mod mi), provided all moduli are pairwise coprime. Failing the coprimality condition means no solution may exist, or the solution is not unique. Manual computation breaks down rapidly as the product M grows, requiring modular inverses via the Extended Euclidean Algorithm at each step. An arithmetic error in any single inverse propagates through the entire sum and produces a wrong answer silently.
This calculator uses arbitrary-precision integer arithmetic (BigInt) to handle moduli of any practical size without overflow. It validates pairwise coprimality before attempting construction and reports exactly which pair of moduli share a common factor. The step-by-step output exposes every intermediate value (Mi, yi, partial products) so you can verify or use them in coursework. Note: CRT applies only when all moduli are pairwise coprime. For non-coprime systems, the generalized CRT requires compatibility conditions on remainders that this tool does not cover.
Formulas
Given k simultaneous congruences:
where all mi are pairwise coprime (gcd(mi, mj) = 1 for i ≠ j), compute the combined modulus:
For each i, compute the partial product and its modular inverse:
The modular inverse yi is found via the Extended Euclidean Algorithm, which solves Mi ⋅ yi + mi ⋅ t = 1. The unique solution modulo M is:
Where ai = remainder for congruence i, mi = modulus for congruence i, M = product of all moduli, Mi = partial product excluding mi, yi = modular inverse of Mi modulo mi, x = unique solution in [0, M − 1].
Reference Data
| System Size | Moduli Example | Product M | Solution x | Domain |
|---|---|---|---|---|
| 2 | 3, 5 | 15 | x ≡ 2 (mod 3), x ≡ 3 (mod 5) → 8 | Textbook intro |
| 3 | 3, 5, 7 | 105 | x ≡ 2, 3, 2 → 23 | Classic puzzle |
| 2 | 7, 11 | 77 | x ≡ 3, 6 → 17 | Cryptography basics |
| 3 | 4, 9, 25 | 900 | x ≡ 1, 2, 3 → 353 | Prime power moduli |
| 4 | 2, 3, 5, 7 | 210 | x ≡ 1, 2, 3, 4 → 53 | Scheduling / cycles |
| 2 | 11, 13 | 143 | x ≡ 7, 9 → 139 | RSA sub-step |
| 3 | 5, 7, 11 | 385 | x ≡ 0, 0, 0 → 0 | Trivial case |
| 2 | 100, 37 | 3700 | x ≡ 55, 22 → 355 | Competition math |
| 5 | 2, 3, 5, 7, 11 | 2310 | x ≡ 1 for all → 1 | All-ones identity |
| 3 | 8, 27, 125 | 27000 | x ≡ 5, 10, 15 → 6265 | Prime power cubes |
| 2 | 17, 19 | 323 | x ≡ 10, 15 → 300 | Number theory HW |
| 4 | 3, 5, 7, 11 | 1155 | x ≡ 2, 4, 6, 10 → 494 | Extended system |
| 2 | 1000000007, 998244353 | ≈ 1018 | Requires BigInt | Competitive programming |