How it’s calculated
The Chinese remainder theorem says that if the moduli m₁, m₂, … are pairwise coprime (no two share a factor), the system x ≡ a₁ (mod m₁), x ≡ a₂ (mod m₂), … always has exactly one solution modulo N = m₁ × m₂ × …. The textbook formula is
This calculator combines the congruences one at a time instead, which also works when the moduli share factors. From x = a + Mk, the next congruence x ≡ b (mod n) becomes Mk ≡ b − a (mod n). With g = gcd(M, n):
- if g does not divide b − a, the congruences contradict each other and there is no solution;
- otherwise divide by g, solve for k with a modular inverse, and the combined modulus is lcm(M, n) = M × n ÷ g.
Example: x ≡ 1 (mod 2), x ≡ 2 (mod 3), x ≡ 3 (mod 5). N = 30, N₁ = 15, N₂ = 10, N₃ = 6, and each yᵢ is 1, so x ≡ 1×15 + 2×10 + 3×6 = 53 ≡ 23 (mod 30). Check: 23 is odd, 23 = 7×3 + 2 and 23 = 4×5 + 3. With shared factors, x ≡ 4 (mod 6) and x ≡ 2 (mod 8) gives 6k ≡ −2 (mod 8), so 3k ≡ −1 (mod 4), k ≡ 1, and x ≡ 10 (mod 24).
Frequently asked questions
What if the moduli are not coprime?
There is a solution exactly when every pair of remainders agrees modulo the GCD of their moduli, and it is unique modulo the LCM of the moduli. For example x ≡ 1 (mod 15) and x ≡ 2 (mod 35) has no solution, because 1 and 2 differ modulo gcd(15, 35) = 5.
Why is the answer a whole family of numbers?
If x works, so does x plus any multiple of the combined modulus, because adding it does not change any of the remainders. The calculator shows the smallest non-negative one and the pattern.
Can a remainder be bigger than its modulus or negative?
Yes. x ≡ 17 (mod 5) means the same as x ≡ 2 (mod 5), and x ≡ −1 (mod 5) means x ≡ 4 (mod 5). The calculator reduces them first.
What is a classic CRT puzzle?
Find a number that leaves remainder 2 when divided by 3, 3 when divided by 5 and 2 when divided by 7. Enter remainders 2, 3, 2 and moduli 3, 5, 7: the answer is 23 (mod 105).
Embed this calculator
Add this free calculator to your own website. Copy the code below into your page’s HTML:
Need this calculator branded, changed or built around your own prices?See custom business solutions →
Sources
- Elementary Number Theory (Raji), §3.4 The Chinese Remainder Theorem (Example 3.4.1: x ≡ 23 mod 30) — LibreTexts Mathematics
- MATH 135 Lecture 31: Chinese Remainder Theorem, including non-coprime moduli (x ≡ 4 mod 6, x ≡ 2 mod 8 gives x ≡ 10 mod 24) — University of Waterloo
- Elementary Number Theory (Raji), §3.3 Linear Congruences — LibreTexts Mathematics
Formulas are taken from the free public references above. Results are provided “as is” for informational and educational purposes only. See our disclaimer.
Added · Last updated · How we check our calculators
Spotted a mistake or missing option? Report a problem· Suggest a calculator