Maths & numbers

Chinese remainder theorem calculator

Combine two congruences with coprime moduli into one exact residue class.

Your numbers

Calculated on your device. Your inputs aren’t sent to us.

Your result

Ready when you are

Enter your numbers and select Calculate.

Behind the numbers

How this calculation works

Start with every number satisfying the first condition. Choose its step multiplier so it satisfies the second. Coprime moduli guarantee one answer modulo their product.

THE FORMULAx = r₁ + m₁k; solve m₁k ≡ r₂−r₁ (mod m₂)

A worked example

x ≡ 2 (mod 3) and x ≡ 3 (mod 5) combine to x ≡ 8 (mod 15).

Good to know

This version handles exactly two coprime moduli. It rejects non-coprime inputs rather than claiming a generalized result. Each modulus is at most one billion; the exact combined answer may exceed JavaScript safe integers and is shown as text.

Combine two clocks into one

Suppose a number leaves remainder 2 after division by 3 and remainder 3 after division by 5. The first condition lets us write x = 2 + 3k. Substitute into the second: 3k ≡ 1 (mod 5), so k ≡ 2 and x ≡ 8 (mod 15).

Because 3 and 5 are coprime, every pair of remainders matches exactly one residue class modulo their product 15. Adding 15 to 8 preserves both conditions. The two verification rows make that claim inspectable.

The linear congruence calculator solves the coefficient step that arises while combining the two conditions.

Use a solver for the right shape

The linear congruence calculator solves a coefficient times one unknown modulo one modulus. This page instead combines two already stated residue conditions. Both use modular inverses internally, but their inputs describe different tasks.

You can apply this two-modulus result again with a third modulus if that third modulus is coprime to the combined modulus. The page itself deliberately stops at two conditions so every step stays visible.

Coprime is a real condition

Non-coprime moduli can sometimes have a compatible combined answer and sometimes conflict. That is a generalized CRT problem, not the claim implemented here. The input is rejected instead of giving a result under a theorem whose prerequisite failed.

Remainders are entered in their standard range from zero through modulus minus one. This makes the displayed smallest non-negative answer unambiguous. Large products are retained as exact whole-number text.

A few questions, answered

Must the moduli be prime?

No. They only need gcd(m₁,m₂)=1.

Is 8 the only integer answer in the example?

No. Every integer congruent to 8 modulo 15 also works.

Can I supply three remainders at once?

This page combines exactly two; a third coprime condition can be combined with the result in a second step.

Find your calculator

Start typing to explore the library.