Chinese Remainder Theorem Calculator

Chinese Remainder Theorem Calculator

Solve systems of linear congruences using the Chinese Remainder Theorem. Useful for number theory, modular arithmetic, and cryptography.

2026-05-24T22:58:31.749Z

Enter integer remainders and positive integer moduli. Moduli must be pairwise coprime.

x ≡(mod)
x ≡(mod)
Solution
x ≡ 7
(mod 15)
All solutions:
x = 7 + 15k
where k ∈ ℤ (any integer)

What is the Chinese Remainder Theorem?

The Chinese Remainder Theorem states that if you have a system of congruences x ≡ a₁ (mod n₁), x ≡ a₂ (mod n₂), ..., x ≡ aₖ (mod nₖ), and the moduli n₁, n₂, ..., nₖ are pairwise coprime, then there is a unique solution modulo M = n₁ × n₂ × ... × nₖ.

This theorem is a central result in number theory and is widely used in modular arithmetic, cryptography, fast arithmetic algorithms, and computational mathematics.

The calculator here uses modular inverses and the extended Euclidean algorithm to construct the solution directly.

How to Use the CRT Calculator

1

Enter Your Congruences

For each congruence x ≡ a (mod n), enter the remainder a and modulus n. All moduli must be positive integers and pairwise coprime.

2

Add or Remove Congruences

Use Add Congruence to extend the system. You can remove entries as long as at least two remain.

3

View the Unique Solution

The calculator shows the smallest nonnegative solution x and the combined modulus M.

4

Understand All Solutions

Once one solution is found, all solutions are given by x = solution + Mk for integer k.

5

Check Error Messages

If moduli are not pairwise coprime, the standard CRT formula does not apply directly.

Real-World Example

Ancient Counting Problem

Scenario:
Find the smallest number x such that x ≡ 2 (mod 3), x ≡ 3 (mod 5), and x ≡ 2 (mod 7).
Step 1:
Multiply the moduli:
M = 3 × 5 × 7 = 105
Step 2:
Compute the partial moduli and inverses:
M₁ = 35, y₁ = 2
M₂ = 21, y₂ = 1
M₃ = 15, y₃ = 1
Step 3:
Combine the pieces:
x = (2·35·2 + 3·21·1 + 2·15·1) mod 105
x = 233 mod 105 = 23
Result:
23

The smallest solution is 23, and all solutions are 23 + 105k.

Frequently Asked Questions

What does pairwise coprime mean?

It means every pair of moduli has greatest common divisor 1.

What if the moduli are not pairwise coprime?

Then the standard CRT may not apply directly. The system may have no solution or require a generalized method.

Does the order of congruences matter?

No. Reordering the congruences does not change the final solution modulo M.

What is a modular inverse?

A modular inverse of a mod m is a number b such that ab ≡ 1 (mod m).

What are practical applications of CRT?

CRT is used in cryptography, modular computation, computer algebra, and fast arithmetic algorithms.

Can CRT be used for nonlinear congruences?

The classical form applies to linear congruences. Nonlinear cases need other methods.

Why is it called the Chinese Remainder Theorem?

The theorem traces back to ancient Chinese mathematics, especially Sunzi’s work.

Why must moduli be positive here?

A modulus should be taken as a positive integer in standard modular arithmetic notation.

Related Tools