StatGardenREF. DESK
Calculators/Maths/Chinese remainder theorem (two congruences)
Maths

Chinese remainder theorem (two congruences) calculator

Finds x satisfying x≡a₁ (mod n₁) and x≡a₂ (mod n₂), including non-coprime moduli.

What this calculator does

Chinese remainder theorem (two congruences) works out finds x satisfying x≡a₁ (mod n₁) and x≡a₂ (mod n₂), including non-coprime moduli. Enter your own figures above and the answer updates as you type: nothing is fixed in the code, so the result reflects exactly the numbers you supply.

The formula this calculator evaluates is printed under the tool and explained below, so you can check the working by hand or reuse it in a spreadsheet.

The formula

FormulaSolvable iff gcd(n₁,n₂) divides (a₂−a₁); solution is unique modulo lcm(n₁,n₂)

The inputs explained

FieldWhat to enter
a₁ (remainder mod n₁)A number. Starts at 2.
n₁ (modulus)A number. Starts at 3.
a₂ (remainder mod n₂)A number. Starts at 3.
n₂ (modulus)A number. Starts at 5.

Worked examples

Every figure in the tables below is produced by this page’s own calculator at build time, so the numbers and the tool always agree. Select any row to load that scenario.

How the answer changes with a₁ (remainder mod n₁)

Every other input is held at the calculator’s starting values while a₁ (remainder mod n₁) varies. Select any row to load that scenario into the calculator.

How the answer changes with a₁ (remainder mod n₁)
a₁ (remainder mod n₁)x ≡ 13 (mod 15)lcm(n₁, n₂)Check: x mod n₁
113151 (should equal 1)
1.5gcd(n₁,n₂) = 1 does not divide (a₂−a₁) = 1.51N/A
28152 (should equal 2)
33150 (should equal 0)
413151 (should equal 1)
63150 (should equal 0)