Chinese Remainder Theorem Calculator
Solve a system of congruences x ≡ a (mod m) with pairwise coprime moduli and get the smallest solution and general form. Example: with remainder a₁ 2, …, the result is Smallest non-negative solution x = 23; General solution = x ≡ 23 (mod 105); Combined modulus M = 105.
Last updated · By S. Dilshan · Runs in your browser, nothing is uploaded
Step-by-Step Solution
How do you use the Chinese Remainder Theorem Calculator?
Enter up to three congruences x ≡ aᵢ (mod mᵢ). Set a modulus to 1 to skip an equation. The moduli must be pairwise coprime. The calculator combines them with the Chinese remainder theorem and shows the smallest non-negative solution, the general solution and a check.
What formula does the Chinese Remainder Theorem Calculator use?
With M = m₁m₂m₃, the solution is x ≡ Σ aᵢ · (M/mᵢ) · yᵢ (mod M), where yᵢ is the inverse of M/mᵢ modulo mᵢ. The theorem guarantees a unique solution modulo M exactly when the moduli are pairwise coprime.
Worked example: Remainder a₁ 2, Modulus m₁ 3, Remainder a₂ 3
Sun Tzu’s classic problem asks for x with x ≡ 2 (mod 3), x ≡ 3 (mod 5) and x ≡ 2 (mod 7). Here M = 105 and the solution is x = 23, since 23 mod 3 = 2, 23 mod 5 = 3 and 23 mod 7 = 2. All solutions are 23 + 105k.
With the default values the calculator returns Smallest non-negative solution x = 23; General solution = x ≡ 23 (mod 105); Combined modulus M = 105; Equations used = x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7).
Where Is This Calculation Used?
The theorem lets you work with a large modulus by splitting it into small coprime ones, a trick used in fast arithmetic, in RSA decryption speed-ups and in puzzles about counting people or objects from their remainders in different groupings.
What are the most common mistakes with the Chinese Remainder Theorem Calculator?
- Using moduli that are not coprime, such as 4 and 6, where a solution may not exist.
- Forgetting that the solution is only defined modulo M.
- Using a wrong modular inverse when combining the equations.
What Is the Tested Example for the Default Values?
This example is computed by the same code that powers the calculator above, so you can compare it with your own numbers or a textbook answer.
| Input: Remainder a₁ | 2 |
|---|---|
| Input: Modulus m₁ | 3 |
| Input: Remainder a₂ | 3 |
| Input: Modulus m₂ | 5 |
| Input: Remainder a₃ | 2 |
| Input: Modulus m₃ | 7 |
| Smallest non-negative solution x | 23 |
| General solution | x ≡ 23 (mod 105) |
| Combined modulus M | 105 |
| Equations used | x ≡ 2 (mod 3), x ≡ 3 (mod 5), x ≡ 2 (mod 7) |
Where Can You Verify These Formulas?
The definitions and formulas on this page follow standard references. Check them against these sources:
Built and maintained by S. Dilshan. Found a mistake? Email [email protected] with the page address.
Frequently Asked Questions
What is the Chinese remainder theorem?
If the moduli are pairwise coprime, a system x ≡ aᵢ (mod mᵢ) has exactly one solution modulo the product of the moduli.
What if the moduli are not coprime?
A solution exists only if the equations agree on the common factors; this calculator requires coprime moduli to avoid ambiguity.
What is the smallest number with remainders 2, 3 and 2 when divided by 3, 5 and 7?
23.