Chinese Remainder Theorem Calculator

Solve systems of congruences using the Chinese Remainder Theorem

System of Congruences

Enter your congruences:

x (mod)
x (mod)

Solution

x 10 (mod 12)
Solution to the system of congruences

Verification:

x ≡ 1 (mod 3)10 ≡ 1 (mod 3)
x ≡ 2 (mod 4)10 ≡ 2 (mod 4)

Step-by-Step Solution:

Step 1: Calculate N = 3 × 4 = 12
Step 2: Calculate Mi = N / ni for each i:
M1 = 12 / 3 = 4
M2 = 12 / 4 = 3
Step 3: Find yi such that Mi × yi ≡ 1 (mod ni):
For M1 = 4, n1 = 3:
4 × 1 ≡ 1 (mod 3)
So y1 = 1
For M2 = 3, n2 = 4:
3 × 3 ≡ 1 (mod 4)
So y2 = 3
Step 4: Calculate x = Σ(ai × Mi × yi) (mod N):
x = 1 × 4 × 1 = 4 + 2 × 3 × 3 = 18
x = 22
x ≡ 10 (mod 12)

Example: Candy Distribution Problem

Problem: Find a number x such that:

• When divided by 3, remainder is 1

• When divided by 4, remainder is 2

• When divided by 5, remainder is 3

x 1 (mod 3)

x 2 (mod 4)

x 3 (mod 5)

Solution: x 58 (mod 60)

Algorithm Steps

1

Calculate N

N = n₁ × n₂ × ... × nₖ

2

Find Mᵢ values

Mᵢ = N / nᵢ for each i

3

Solve for yᵢ

Mᵢ × yᵢ 1 (mod nᵢ)

4

Combine

x = Σ(aᵢ × Mᵢ × yᵢ) mod N

Requirements

All moduli must be greater than 1

Moduli must be pairwise coprime

Solution is unique modulo N

ℹ️

Works for any number of congruences

Understanding the Chinese Remainder Theorem

What is the Chinese Remainder Theorem?

The Chinese Remainder Theorem (CRT) provides a way to solve systems of simultaneous congruences with pairwise coprime moduli. It guarantees a unique solution modulo the product of all moduli.

Key Requirements

  • Moduli must be pairwise coprime (gcd of any pair = 1)
  • All moduli must be positive integers greater than 1
  • Solution exists and is unique modulo N = n₁ × n₂ × ... × nₖ

Mathematical Foundation

System of Congruences:

x a₁ (mod n₁)

x a₂ (mod n₂)

x aₖ (mod nₖ)

Applications

  • Cryptography (RSA algorithm)
  • Computer science algorithms
  • Calendar calculations
  • Number theory problems

Historical Context

Despite its name, the Chinese Remainder Theorem was not originally from China. The earliest known statement appears in the work of the Chinese mathematician Sun Tzu (not the military strategist) around 3rd-5th century CE. The theorem was later rediscovered and formalized by European mathematicians in the 18th century.