Chinese Remainder Theorem Calculator
Solve two simultaneous congruences with coprime moduli and get the unique answer modulo their product.
What it does
The Chinese remainder theorem solves systems of congruences with different moduli. For two congruences with coprime moduli, it guarantees exactly one solution modulo the product of the moduli.
This tool takes two remainders and their moduli. It checks that the moduli are coprime, finds one solution using Bezout coefficients, and reduces it to the smallest nonnegative representative.
The page opens with x congruent to 6 modulo 9 and x congruent to 4 modulo 11. The solution is 15 modulo 99, because 15 leaves remainder 6 on division by 9 and remainder 4 on division by 11.
The construction writes the second congruence in terms of the first and uses the modular inverse of the first modulus relative to the second. That is why the extended Euclidean algorithm appears in the background.
If the moduli share a common factor, a solution may not exist or may not be unique in the same way. This two congruence tool rejects such inputs instead of returning a misleading answer.
How to use
- Enter the first remainder and modulus.
- Enter the second remainder and modulus.
- Confirm the two moduli are coprime.
- Read the smallest nonnegative solution as the main result.
- Check the combined modulus, which is the product of the two moduli.
- Use the two check rows to verify the remainders.
Formula
- a1, a2
- The target remainders of the two congruences.
- m1, m2
- Coprime moduli.
- solution
- The smallest nonnegative x satisfying both congruences.
Writing x equals a1 plus m1 times y reduces the second congruence to m1 times y congruent to a2 minus a1 modulo m2. Multiplying by the inverse of m1 modulo m2 gives y, and hence x. The solution is then reduced into the range zero to m1 times m2 minus one.
Worked example
Example: mod 9 and mod 11
The page opens with x = 6 mod 9 and x = 4 mod 11.
- Check that 9 and 11 are coprime, so a unique solution exists modulo 99.
- Write x as 6 plus 9y.
- The second congruence requires 6 plus 9y congruent to 4 modulo 11.
- So 9y is congruent to minus 2, or 9, modulo 11.
- The inverse of 9 modulo 11 is 5, so y is congruent to 5 times 9, which is 45, or 1 modulo 11.
- Taking y = 1 gives x = 15, which the tool reports with combined modulus 99.
Reference table
| System | Smallest solution | Combined modulus |
|---|---|---|
| x = 6 mod 9, x = 4 mod 11 | 15 | 99 |
| x = 2 mod 3, x = 3 mod 5 | 8 | 15 |
Limits
- Handles exactly two congruences.
- Moduli must be coprime whole numbers from 2 to 1,000,000,000.
- Returns the smallest nonnegative representative only.
- All solutions differ by multiples of the combined modulus.
Common mistakes
- Using moduli that share a common factor.
- Forgetting that the solution is unique only modulo the product.
- Reporting a negative representative when a nonnegative one exists.
- Mixing up which remainder belongs to which modulus.
- Assuming every pair of congruences has a solution.
Try it yourself
Quick checks. Answers sit tucked under each question.
x = 2 mod 3 and x = 3 mod 5. Smallest solution?
8, with combined modulus 15.
What is the combined modulus in the default example?
99, the product of 9 and 11.
What if the moduli are not coprime?
The tool reports an error because the two congruence version requires coprime moduli.
Questions
What does the theorem guarantee?
A unique solution modulo the product when the moduli are pairwise coprime.
Why must the moduli be coprime?
Otherwise the modular inverse needed in the construction may not exist.
How is the solution found?
By substituting one congruence into the other and using a modular inverse from the extended Euclidean algorithm.
Are there other solutions?
Yes. Adding any multiple of the product of the moduli gives another solution.
Can there be more than two congruences?
Yes, but this tool handles two. The general case needs all moduli pairwise coprime.
Where is this used?
It appears in cryptography, hashing and efficient computation with large integers.
Sources
- University of Connecticut, Keith Conrad notes on the Chinese remainder theorem
- MIT OpenCourseWare, lecture 5 on the Chinese remainder theorem
- Millersville University, Chinese remainder theorem notes