Chinese Remainder Theorem Solver

Use this Chinese Remainder Theorem Solver to enter values, adjust options, and review results in a compact responsive workspace.

Results are calculated automatically as you enter data.

Chinese Remainder Theorem Solver

One congruence per row
Residue a Modulus m

Use the import modal to paste multiple congruences at once.

Construction with modular inverses
Result Enter at least two congruences.

▼ See explanations and tips below ▼

What Is the Chinese Remainder Theorem?

The Chinese Remainder Theorem is a result in modular arithmetic. It helps solve systems where the same unknown integer has several different remainders when divided by different moduli.

A typical system looks like this:

$$ \begin{aligned} x &\equiv a_1 \pmod{m_1} \\ x &\equiv a_2 \pmod{m_2} \\ &\vdots \\ x &\equiv a_n \pmod{m_n} \end{aligned} $$

Each line says something about the remainder of \(x\). For example, \(x \equiv 2 \pmod{3}\) means that \(x\) leaves a remainder of \(2\) when divided by \(3\).

In its standard form, the theorem says that if the moduli \(m_1, m_2, \ldots, m_n\) are pairwise coprime, then the system has one solution modulo the product \(m_1m_2\cdots m_n\). In other words, there is one residue class that satisfies all the congruences, and every solution differs from that residue by a multiple of the combined modulus.

The generalized version extends the idea to some systems where the moduli are not pairwise coprime. In that case, the system may still have a solution, but only when the residues are compatible with the common factors of the moduli.


Why the Chinese Remainder Theorem Matters

The theorem is useful because it turns several remainder conditions into one compact answer. Instead of listing many congruences separately, you can combine them into a single congruence:

$$ x \equiv r \pmod{M} $$

That form is easier to interpret, compare, and reuse.

The Chinese Remainder Theorem is common in elementary number theory, discrete mathematics, and modular arithmetic problems. It also appears in computational settings where a calculation can be split into smaller modular calculations and then recombined.

Even in simple word problems, the theorem gives a clean way to handle repeated cycles. If a number must fit several repeating patterns at the same time, a CRT-style congruence system is often the natural mathematical model.


Key Terms to Know

  • Congruence: A statement such as \(x \equiv a \pmod{m}\), meaning \(x\) and \(a\) have the same remainder when divided by \(m\).
  • Residue: The remainder value in a congruence. In \(x \equiv 2 \pmod{5}\), the residue is \(2\).
  • Modulus: The divisor that defines the cycle. In \(x \equiv 2 \pmod{5}\), the modulus is \(5\).
  • Congruence class: The full set of integers that satisfy one congruence. For example, \(x \equiv 2 \pmod{5}\) includes \(\ldots, -8, -3, 2, 7, 12, \ldots\).
  • Pairwise coprime: A set of moduli is pairwise coprime when every pair has greatest common divisor \(1\).
  • Greatest common divisor: The largest positive integer that divides two integers. It is often written as \(\gcd(m,n)\).
  • Least common multiple: The smallest positive integer that is a multiple of two or more integers. It is often written as \(\operatorname{lcm}(m,n)\).
  • Modular inverse: An integer that undoes multiplication modulo another integer. If \(uv \equiv 1 \pmod{m}\), then \(v\) is a modular inverse of \(u\) modulo \(m\).

How the Chinese Remainder Theorem Works

The standard CRT starts with pairwise coprime moduli. For example, \(3\), \(5\), and \(7\) are pairwise coprime because every pair has greatest common divisor \(1\).

For pairwise coprime moduli, the combined modulus is the product:

$$ M = m_1m_2\cdots m_n $$

The result is unique modulo \(M\). That does not mean there is only one integer solution. It means there is one solution class:

$$ x = r + Mk $$

where \(k\) can be any integer.

For two congruences, the generalized method can be understood through a simple reduction. Suppose you want to solve:

$$ \begin{aligned} x &\equiv a \pmod{m} \\ x &\equiv b \pmod{n} \end{aligned} $$

The first congruence means \(x\) can be written as:

$$ x = a + mt $$

Substitute that into the second congruence:

$$ a + mt \equiv b \pmod{n} $$

Then subtract \(a\):

$$ mt \equiv b-a \pmod{n} $$

This is a linear congruence. Let:

$$ g = \gcd(m,n) $$

A solution exists only when \(b-a\) is divisible by \(g\):

$$ g \mid (b-a) $$

If that condition fails, the two congruences contradict each other. If it holds, the pair can be combined into one congruence modulo:

$$ \operatorname{lcm}(m,n) = \frac{mn}{g} $$

After combining one pair, the same idea can be repeated with the next congruence until the system is reduced to one final congruence.


Examples of the Chinese Remainder Theorem in Practice

Example 1: Pairwise coprime moduli

Solve:

$$ \begin{aligned} x &\equiv 2 \pmod{3} \\ x &\equiv 3 \pmod{5} \\ x &\equiv 2 \pmod{7} \end{aligned} $$

The moduli \(3\), \(5\), and \(7\) are pairwise coprime, so the combined modulus is:

$$ M = 3 \times 5 \times 7 = 105 $$

Testing or applying the CRT gives:

$$ x \equiv 23 \pmod{105} $$

Check the result:

$$ 23 \equiv 2 \pmod{3}, \qquad 23 \equiv 3 \pmod{5}, \qquad 23 \equiv 2 \pmod{7} $$

So every solution has the form:

$$ x = 23 + 105k $$

where \(k\) is any integer.


Example 2: Compatible non-coprime moduli

Non-coprime moduli do not automatically mean failure. Consider:

$$ \begin{aligned} x &\equiv 2 \pmod{6} \\ x &\equiv 8 \pmod{10} \end{aligned} $$

The moduli are not coprime because:

$$ \gcd(6,10) = 2 $$

Now compare the residues:

$$ 8 - 2 = 6 $$

Since \(6\) is divisible by \(2\), the congruences are compatible.

Start with \(x = 2 + 6t\) and substitute into the second congruence:

$$ 2 + 6t \equiv 8 \pmod{10} $$
$$ 6t \equiv 6 \pmod{10} $$

Divide by the common factor \(2\):

$$ 3t \equiv 3 \pmod{5} $$

The inverse of \(3\) modulo \(5\) is \(2\), so:

$$ t \equiv 3 \times 2 \equiv 6 \equiv 1 \pmod{5} $$

Using \(t=1\) gives:

$$ x = 2 + 6(1) = 8 $$

The combined modulus is:

$$ \operatorname{lcm}(6,10) = 30 $$

So the solution is:

$$ x \equiv 8 \pmod{30} $$

Example 3: Incompatible non-coprime moduli

Now consider:

$$ \begin{aligned} x &\equiv 1 \pmod{4} \\ x &\equiv 2 \pmod{6} \end{aligned} $$

The greatest common divisor is:

$$ \gcd(4,6) = 2 $$

The difference between the residues is:

$$ 2 - 1 = 1 $$

Since \(1\) is not divisible by \(2\), the two conditions are incompatible. There is no integer that is both congruent to \(1\) modulo \(4\) and congruent to \(2\) modulo \(6\).


How to Interpret the Result

A result such as:

$$ x \equiv r \pmod{M} $$

means that \(r\) is the least nonnegative residue of the solution class and \(M\) is the combined modulus. Every integer solution is obtained by adding or subtracting multiples of \(M\):

$$ x = r + Mk $$

where \(k\) is any integer.

The combined modulus is the period of the answer. Once one solution is known, the next larger solution is \(M\) units away, and the next smaller solution is also \(M\) units away.

The smallest positive solution is usually \(r\), but there is one important exception. If the least nonnegative residue is \(0\), then the smallest positive solution is \(M\), not \(0\), because \(0\) is not positive.

If the result says the moduli are pairwise coprime, the standard Chinese Remainder Theorem applies directly. If the moduli are not pairwise coprime, the system can still have a valid solution when the residues agree modulo the relevant greatest common divisors.

An incompatibility message means the congruences do not have a common integer solution. In practical terms, at least two of the remainder conditions require different answers modulo a shared factor.


Common Mistakes and Misconceptions

  • Assuming the moduli must be prime: The standard theorem requires pairwise coprime moduli, not necessarily prime moduli. For example, \(4\) and \(9\) are not prime, but they are coprime.
  • Assuming every non-coprime system fails: Some non-coprime systems are compatible. The key test is whether the residues agree modulo the greatest common divisor.
  • Confusing \(r\) and \(M\): In \(x \equiv r \pmod{M}\), \(r\) is the residue and \(M\) is the modulus. They play different roles.
  • Thinking the result is only one number: A CRT result describes a full class of integers, not just one integer.
  • Forgetting residue normalization: A residue such as \(-1\) modulo \(5\) is equivalent to \(4\) modulo \(5\), because both represent the same congruence class.
  • Expecting decimal inputs to work: Modular congruence systems use integers. Fractions and decimals are not part of the usual CRT setup.
  • Calling \(0\) the smallest positive solution: If the solution class is \(x \equiv 0 \pmod{M}\), the smallest positive solution is \(M\).

When to Use the Chinese Remainder Theorem

Use the Chinese Remainder Theorem when you need to combine several remainder conditions for the same unknown integer.

Common use cases include:

  • Solving number theory and discrete mathematics exercises.
  • Combining congruences with pairwise coprime moduli.
  • Checking whether non-coprime congruences are compatible.
  • Modeling repeated cycles that must line up at the same value.
  • Reducing a modular calculation into smaller modular pieces and recombining the result.

The theorem is most helpful when each condition is naturally written as a congruence. If the problem involves inequalities, real numbers, measurement error, or approximate data, the CRT may not be the right tool without additional modeling.


Limitations and Things to Keep in Mind

The CRT is an integer theorem. The residues and moduli should be integers, and each modulus should be positive. A modulus of \(0\) or a negative modulus is not valid.

This calculator treats the result as exact. It does not round decimal values, because the calculation is based on integer arithmetic. Entered residues are reduced to their least nonnegative form, so a residue outside the usual range still represents the same congruence class after normalization.

Type integer inputs plainly, such as 3 or -3. Decimal values, fractions, scientific notation such as 1e6, and explicit leading plus signs such as +3 are not supported.

At least two congruences are needed for a system. A single congruence is already a solution class, so there is nothing to combine.

For non-coprime moduli, a solution exists only when the residue conditions are compatible with the shared factors. If the compatibility test fails, there is no combined congruence to report.

Very large systems can produce very large combined moduli. The algebraic result can still be exact, but visual residue grids are only practical for small combined moduli. This calculator shows a full residue grid only when the combined modulus is at most \(72\); for larger combined moduli, viewing sample solution values is usually clearer than trying to display the whole residue cycle.


How to Use This Calculator

  1. Enter an integer residue and a positive integer modulus for each congruence row.
  2. Use at least two rows. Add more rows when your system has more congruences.
  3. You may enter residues outside the range \(0\) to \(m-1\); they will be interpreted modulo the row's modulus.
  4. If you paste a system, use a supported plain-text format such as x ≡ 2 (mod 3), x == 2 mod 3, x = 2 mod 3, 2, 3, or 2 3.
  5. Read the main result as \(x \equiv r \pmod{M}\).
  6. Use the full solution form \(x = r + Mk\) to describe all integer solutions.
  7. Review the row checks and step-by-step formulas when you want to confirm how the combined result was built.

Frequently Asked Questions

Does the Chinese Remainder Theorem require prime moduli?

No. The standard version requires the moduli to be pairwise coprime. Prime moduli are one way to guarantee that, but composite moduli can also be pairwise coprime.


Can non-coprime moduli have a solution?

Yes. A non-coprime system can have a solution when the residues agree modulo the greatest common divisor of the moduli involved. If the residues disagree modulo a shared factor, the system has no common solution.


What does \(x = r + Mk\) mean?

It means every solution is found by choosing an integer value for \(k\). Positive, negative, and zero values of \(k\) all give valid solutions in the same congruence class.


Why is the combined modulus sometimes the least common multiple instead of the product?

When moduli are pairwise coprime, their least common multiple equals their product. When moduli share factors, the least common multiple is smaller than the product, and it becomes the period of the combined solution class when a compatible solution exists.


What happens to negative residues?

Negative residues are another way to name the same congruence class. For example, \(-1 \pmod{5}\) is the same as \(4 \pmod{5}\), so a solver can normalize \(-1\) to \(4\) before combining congruences.


Why might the calculator say there is no solution?

A no-solution result means the congruences conflict. For two congruences, this happens when the difference between the residues is not divisible by the greatest common divisor of the moduli.


Sources and References

Books and Open Textbooks

  1. Mike Barrus and W. Edwin Clark. Elementary Number Theory. Mathematics LibreTexts. Section 1.23, “Chinese Remainder Theorem.” Accessed June 27, 2026. LibreTexts page
  2. Wissam Raji. Elementary Number Theory. Mathematics LibreTexts. Chapter 3, Section 3.3, “Linear Congruences.” Accessed June 27, 2026. LibreTexts page
  3. Pamini Thangarajah. MATH 2150: Higher Arithmetic. Mathematics LibreTexts, Mount Royal University. Section 4.5, “Linear Congruences.” Accessed June 27, 2026. LibreTexts page

Online Educational and Technical Sources

  1. Keith Conrad. “The Chinese Remainder Theorem.” University of Connecticut mathematics notes. Accessed June 27, 2026. PDF
  2. Maplesoft. “Generalized Chinese Remainder Algorithm.” Maple Online Help, NumberTheory[ChineseRemainder]. Accessed June 27, 2026. Maple Online Help page