Chinese Remainder Theorem

Last Updated : 5 Dec, 2025

Chinese Remainder Theorem is a mathematical principle that solves systems of modular equations by finding a unique solution from the remainder of the division. It is used in cryptography and computer science for efficient computation.

According to the Theorem, if in a given set of equations, each equation has a different number (say, n1, n2, ..., nk), and these numbers are all relatively prime to each other, and also have some numbers (say, a1, a2,..., ak), then there is a unique solution (let's call it x) that satisfies all the equations at once.

This solution is found modulo the product of all the numbers (N = n1 · n2 ·...· nk). Therefore, x satisfies each equation by leaving the same remainder when divided by its corresponding number (ni) as the given number (ai).


In simpler terms, the theorem states:

"If a number is divided by several other numbers that have no common factors, one can find the remainder when dividing by the product of those numbers."

The solution is unique modulo N, meaning any other solution is congruent to the original one modulo N.

Statement of Chinese Remainder Theorem

The Chinese Remainder Theorem states that a system of simultaneous congruences, defined by pairwise coprime positive integers (n1, n2,...., nk ) and arbitrary integers (a1, a2,...., ak ) such as:

x ≡ a1 (mod n1)

x ≡ a2 (mod n2)

x ≡ ak (mod nk)

there exists a unique solution x modulo (N = n1 n2 .... nk) that satisfies all the congruances simultaneously.

Chinese Remainder Theorem Proof

To prove Chinese remainder theorem, let us find an integer (x) that satisfies: x ≡ ai (mod ni) for each (i = 1, 2,...., k).

We define (Ni = N/ni).

Since (ni) and (Ni) are coprime, according to Bézout's identity, there are integers (si) and (ti) such that:

si·ni + ti·Ni = 1

We set (yi = ti·Ni)

Now, let's construct (x) as follows,

x = \sum_{i=1}^k a_i \cdot y_i

This solution satisfies all the congruences, i.e., x ≡ ai (mod ni) for each (i). To see this, observe:

x ≡ ai·yi ≡ ai·ti·Ni ≡ ai·1 ≡ ai

Thus, (x) is a solution to the system of congruences.

Uniqueness:

Suppose (x) and (x') are two solutions to the system of congruences. We aim to show that (x ≡ x' (mod N).

Let (m = x' - x). Since both (x) and (x') satisfy all the congruences, (m) must also satisfy them. Therefore, (m) is divisible by each of the moduli (n1, n2,...., nk).

By definition, (N = n1 · n2 ·....· nk). As (m) is divisible by each (ni), it is also divisible by (N), i.e., m ≡ 0 (mod N).

Hence, x ≡ x' (mod N, establishing uniqueness).

Necessary Condition for Chinese Remainder Theorem

For the Chinese Remainder Theorem to work, the numbers we are dividing by must not have any common factors. So, if there are two numbers that are being divided by, say (mi) and (mj), then they can not common factors other than 1. That means their biggest shared factor, called the greatest common divisor is 1.

GCD(mi, mj) = 1

This condition ensures that the system of congruences is consistent and that the solution provided by the Chinese Remainder Theorem is unique modulo the product of the moduli. If the moduli are not pairwise coprime, then the theorem may not yield a solution, or the solution may not be unique. Therefore, pairwise coprimality is a fundamental requirement for the application of the Chinese Remainder Theorem.

Chinese Remainder Theorem Solution for Two Moduli

Chinese Remainder Theorem provides a solution for systems of congruences involving two moduli. Given two pairwise coprime moduli (m1) and (m2), and their respective residues (a1) and (a2), the theorem states that there exists a unique solution modulo (m1 × m2) for the system of congruences:
x ≠ a1 mod m1

x ≠ a2 mod m2

The solution can be found using the formula:

x = a_1 + m_1 \left( \frac{{a_2 - a_1}}{{m_1}} \right) \left( \frac{{m_1^{-1}}}{{m_2}} \right) \ (\text{mod}\ (m_1 \times m_2))

Where (m1-1) denotes the modular multiplicative inverse of (m1) modulo (m2). This inverse can be found using methods such as the Extended Euclidean Algorithm.

Extended Euclidean Algorithm: Computes the gcd of two integers a and b, along with integers x and y(called Bézout coefficients) such that: a⋅x+b⋅y=gcd⁡(a,b). where,

  • Two integers a and b (a>b).
  • gcd⁡(a, b): Greatest common divisor.
  • x, y : Integers satisfying a⋅x + b⋅y = gcd⁡(a, b)

It is widely used to find modular inverses (critical in cryptography).

Chinese Remainder Theorem Solution for General Case

Chinese Remainder Theorem (CRT) provides a solution for a system of congruences with arbitrary moduli. Suppose we have a system of congruences:

x \equiv a_1 \ (\text{mod}\ m_1)

x \equiv a_2 \ (\text{mod}\ m_2)

x \equiv a_n \ (\text{mod}\ m_n)

Where (m1, m2, ..., mn) are pairwise coprime moduli and (a1, a2, ..., an) are the corresponding residues.

CRT states that there exists a unique solution modulo (M = m1 × m2 × ... × mn) for this system of congruences. The solution can be found using the formula:

x \equiv \sum_{i=1}^{n} a_i M_i y_i \ (\text{mod}\ M)

Where (Mi = M / mi) and (yi) is the modular multiplicative inverse of (Mi) modulo (mi).

Suppose we have the following system of congruences:

x ≡ 2 mod 3

x ≡ 3 mod 5

x ≡ 2 mod 7

Calculate M = 3 × 5 × 7 = 105

Then, we calculate (M1 = 105 / 3 = 35), (M2 = 105 / 5 = 21), and (M3 = 105 / 7 = 15).

find the modular multiplicative inverses (y1), (y2), and (y3) for (M1), (M2), and (M3) modulo (m1), (m2), and (m3), respectively

y1 is the modular multiplicative inverse of 35 modulo 3, which is 2

y2 is the modular multiplicative inverse of 21 modulo 5, which is 1

y3 is the modular multiplicative inverse of 15 modulo 7, which is 1

Now, using the formula:

x ≡ 2 × 35 × 2 + 3 × 21 × 1 + 2 × 15 × 1 (mod 105)

x ≡ 140 + 63 + 30 mod 105)

x ≡ 233 mod 105)

So, the solution for the system of congruences is x ≡ 233 (mod 105)

Chinese Remainder Theorem Solution for Not Coprime Moduli

Chinese Remainder Theorem helps in solving systems of equations where the remainders are congruent, even if the numbers that are divisible by are not relatively prime. But when the divisors are not relatively prime, there might be more than one solution to the problem.

Suppose we have the following system of congruences:

x ≡ 2 (mod 4)

x ≡ 6 (mod 6)

Here, the moduli 4 and 6 are not coprime because their greatest common divisor (GCD) is 2

To find the solution using the Chinese Remainder Theorem, we proceed as follows:

1. Find the moduli product: Calculate (m = 4 × 6 = 24).

2. Find the residues: Divide each modulus by the product of the other moduli to find the residue:

  • 4 × k ≡ 1 (mod 6)
  • 6 × k' ≡ 1 (mod 4)

In this case, (k = 1) and (k' = 1) satisfy the congruences, so the residues are both 1

3. Calculate the solution: The solution (x) is given by: x = a1 × m2 × k + a2 × m1 × k' (mod m)

Plugging in the values:

  • x = 2 × 6 × 1 + 6 × 4 × 1...(mod 24)
  • x = 12 + 24...(mod 24)
  • x = 36...(mod 24)
  • x = 12

So, the solution for this system of congruences is x ≡ 12 (mod 24).

Also Check:

Application of Chinese Remainder Theorem in Computer Science

Applications of the Chinese remainder theorem are as follows:

Cryptography

  • RSA Decryption is optimized using CRT. RSA decryption computes m ≡ cd mod  N, where N=p×q (large primes). Direct computation is slow for large N and CRT does the process of direct exponentiation ~4x faster.
  • CRT enables parallel processing of encrypted data by splitting computations across smaller residues. Used in secure multi-party computation (MPC) and private AI training.

Error correction

  • Reed-Solomon Codes recover data from corrupted storage (e.g., CDs, QR codes) by encoding data as residues modulo coprime numbers. Even if some residues are lost/corrupted, original data can be reconstructed. Ex.: RAID storage systems, satellite communications.
  • Checksum Algorithms CRT-based checksums detect errors in distributed databases.

Parallel Computing

  • Residue Number Systems (RNS), As large integer arithmetic is slow due to carry propagation. CRT represent numbers as residues modulo small primes and perform carry-free parallel arithmetic (addition, multiplication).
  • GPU Acceleration, CRT decomposes problems into independent sub-tasks, ideal for massively parallel GPU computing.

Quantum Computing

  • For Quantum Error Correction, CRT helps design fault-tolerant quantum gates by decomposing operations into smaller moduli.
  • In Shor’s Algorithm, CRT is used in the final step to reconstruct the prime factors of large integers.

Algorithmic Optimizations

  • For Fast Fourier Transform (FFT), CRT enables multidimensional FFTs by breaking signals into smaller residues.
  • In Knuth’s Modular Multiplication, CRT speeds up large-integer multiplication in cryptographic libraries.

Solved Example on Chinese Remainder Theorem

Suppose a certain number leaves a remainder of 2 when divided by 3, a remainder of 3 when divided by 5, and a remainder of 2 when divided by 7. Find the smallest positive integer that satisfies these conditions using the Chinese Remainder Theorem.

Solution:

Let x be the number that satisfies all the given conditions:

  • Remainder of 2 when divided by 3
  • Remainder of 3 when divided by 5
  • Remainder of 2 when divided by 7

Now, as per the Chinese Remainder Theorem, since the moduli (3, 5, and 7) are pairwise coprime, a unique solution modulo is lcm(3,5,7)=105

  • x ≡ 2(mod 3)
  • x ≡ 3(mod 5)
  • x ≡ 2(mod 7)

The modular inverses for each modulus will be:

  • For 3, the modular inverse of 3 modulo 5 is 2 as 3⋅2 ≡ 1(mod 5)
  • For 5, the modular inverse of 5 modulo 7 is 3 as 5⋅3 ≡ 1(mod 7)
  • For 7, the modular inverse of 7 modulo 3 is 1 as 7⋅1 ≡ 1(mod 3)

Now calculate for x:

x ≡ (2⋅35⋅2)⋅(2⋅3) + (3⋅3⋅7⋅1) + (2⋅3⋅5)⋅(1⋅1)...(mod 105)

On solving each term we get,

x ≡ 140 + 63 + 30(mod105)

x ≡ 233(mod105)

x ≡ 23(mod105)

∴ Smallest positive integer that satisfies the given conditions is x=23.

Practice Questions on Chinese Remainder Theorem

Question 1: Solve the system of congruences:

x ≡ 2 (mod 3)
x ≡ 3 (mod 5)
x ≡ 2 (mod 7)

Question 2: Solve the system of congruences:

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

Answer Key

  1. x = 23 (modulo 105).
  2. There is no solution for this system of congruences,  because x ≡ 1 (mod2) (odd) and x ≡ 2 (mod4) (even) are contradictory.
Comment

Explore