Skip to content

Chinese Remainder Theorem

The Chinese remainder theorem describes when several congruence conditions can be combined into one congruence. Its cleanest form occurs when the moduli are pairwise coprime.

Independent Congruence Conditions

The Chinese remainder theorem describes when several congruence conditions can be combined into one congruence. Its cleanest form occurs when the moduli are pairwise coprime.

Suppose

n1,n2,,nr n_1,n_2,\ldots,n_r

are positive integers satisfying

gcd(ni,nj)=1 \gcd(n_i,n_j)=1

whenever

ij. i\ne j.

Then the congruences

xa1(modn1), x\equiv a_1\pmod{n_1}, xa2(modn2), x\equiv a_2\pmod{n_2}, \cdots xar(modnr) x\equiv a_r\pmod{n_r}

have a unique solution modulo

N=n1n2nr. N=n_1n_2\cdots n_r.

This means all integer solutions form exactly one residue class modulo NN.

The Case of Two Moduli

First consider

xa(modm), x\equiv a\pmod m, xb(modn), x\equiv b\pmod n,

where

gcd(m,n)=1. \gcd(m,n)=1.

Write

x=a+mk. x=a+mk.

Substituting into the second congruence gives

a+mkb(modn). a+mk\equiv b\pmod n.

Thus

mkba(modn). mk\equiv b-a\pmod n.

Since

gcd(m,n)=1, \gcd(m,n)=1,

the integer mm has an inverse modulo nn. Therefore this linear congruence has a unique solution modulo nn. Once kk is determined, x=a+mkx=a+mk gives a solution to the original system.

The solution is unique modulo mnmn.

Example

Solve

x2(mod3), x\equiv2\pmod3, x3(mod5). x\equiv3\pmod5.

Write

x=2+3k. x=2+3k.

Then

2+3k3(mod5), 2+3k\equiv3\pmod5,

so

3k1(mod5). 3k\equiv1\pmod5.

Since

312(mod5), 3^{-1}\equiv2\pmod5,

we get

k2(mod5). k\equiv2\pmod5.

Thus

k=2+5t. k=2+5t.

Hence

x=2+3(2+5t)=8+15t. x=2+3(2+5t)=8+15t.

Therefore

x8(mod15). x\equiv8\pmod{15}.

Constructive Formula

The theorem also has an explicit constructive formula.

Let

N=n1n2nr. N=n_1n_2\cdots n_r.

For each ii, define

Ni=Nni. N_i=\frac{N}{n_i}.

Since the moduli are pairwise coprime,

gcd(Ni,ni)=1. \gcd(N_i,n_i)=1.

Therefore NiN_i has an inverse modulo nin_i. Choose yiy_i such that

Niyi1(modni). N_i y_i\equiv1\pmod{n_i}.

Then a solution is

xi=1raiNiyi(modN). x\equiv \sum_{i=1}^{r} a_iN_iy_i \pmod N.

To see why, reduce this expression modulo njn_j. If iji\ne j, then njNin_j\mid N_i, so

aiNiyi0(modnj). a_iN_iy_i\equiv0\pmod{n_j}.

Only the jj-th term remains:

xajNjyjaj(modnj). x\equiv a_jN_jy_j\equiv a_j\pmod{n_j}.

Thus the formula satisfies every congruence.

Example with Three Moduli

Solve

x2(mod3), x\equiv2\pmod3, x3(mod5), x\equiv3\pmod5, x2(mod7). x\equiv2\pmod7.

The moduli are pairwise coprime, and

N=357=105. N=3\cdot5\cdot7=105.

Compute

N1=35,N2=21,N3=15. N_1=35, \qquad N_2=21, \qquad N_3=15.

Now find inverses:

352(mod3), 35\equiv2\pmod3,

and

212(mod3), 2^{-1}\equiv2\pmod3,

so

y1=2. y_1=2.

Next,

211(mod5), 21\equiv1\pmod5,

so

y2=1. y_2=1.

Finally,

151(mod7), 15\equiv1\pmod7,

so

y3=1. y_3=1.

Therefore

x2352+3211+2151(mod105). x\equiv 2\cdot35\cdot2 + 3\cdot21\cdot1 + 2\cdot15\cdot1 \pmod{105}.

This gives

x140+63+30=233(mod105). x\equiv140+63+30=233\pmod{105}.

Since

23323(mod105), 233\equiv23\pmod{105},

the solution is

x23(mod105). x\equiv23\pmod{105}.

Uniqueness

Suppose xx and xx' both solve the same system. Then for every ii,

xx(modni). x\equiv x'\pmod{n_i}.

Thus

ni(xx) n_i\mid(x-x')

for each ii.

Since the nin_i are pairwise coprime, their product divides xxx-x':

N(xx). N\mid(x-x').

Therefore

xx(modN). x\equiv x'\pmod N.

This proves uniqueness modulo NN.

Ring Form

The Chinese remainder theorem can be expressed as an isomorphism of rings:

Z/NZZ/n1Z×Z/n2Z××Z/nrZ, \mathbb{Z}/N\mathbb{Z} \cong \mathbb{Z}/n_1\mathbb{Z} \times \mathbb{Z}/n_2\mathbb{Z} \times \cdots \times \mathbb{Z}/n_r\mathbb{Z},

where

N=n1n2nr N=n_1n_2\cdots n_r

and the moduli are pairwise coprime.

The map sends a residue class [x]N[x]_N to

([x]n1,[x]n2,,[x]nr). ([x]_{n_1},[x]_{n_2},\ldots,[x]_{n_r}).

The theorem says this map is bijective and respects addition and multiplication.

General Compatibility

If the moduli are not pairwise coprime, a system may still have solutions, but compatibility conditions are required.

The system

xai(modni) x\equiv a_i\pmod{n_i}

is solvable exactly when

aiaj(modgcd(ni,nj)) a_i\equiv a_j\pmod{\gcd(n_i,n_j)}

for every pair i,ji,j.

When solvable, the solution is unique modulo

lcm(n1,n2,,nr). \operatorname{lcm}(n_1,n_2,\ldots,n_r).

Thus the pairwise coprime case is the special case where all compatibility conditions are automatic.

Role in Number Theory

The Chinese remainder theorem shows that arithmetic modulo a product of coprime moduli decomposes into independent arithmetic modulo each factor.

This principle is fundamental in modular arithmetic, computation, cryptography, algebraic number theory, and local-global reasoning.

It lets one replace a difficult congruence modulo NN by several simpler congruences modulo the prime-power factors of NN. This is one of the main ways number theory breaks a global problem into local pieces.