MathorynMathematical Formula Database

Number Theory

Chinese Remainder Theorem

A system of congruences with pairwise coprime moduli has exactly one solution modulo the product of the moduli. It is used in cryptography (RSA speed-ups), calendar calculations and to split computations into smaller moduli.

x≡ai(modmi), gcd⁡(mi,mj)=1 ⇒ a unique x  mod  m1m2⋯mkx\equiv a_i\pmod{m_i},\ \gcd(m_i,m_j)=1\ \Rightarrow\ \text{a unique}\ x\ \bmod\ m_1m_2\cdots m_k
LaTeXx\equiv a_i\pmod{m_i},\ \gcd(m_i,m_j)=1\ \Rightarrow\ \text{a unique}\ x\ \bmod\ m_1m_2\cdots m_k

Variables

aia_i
remainders
mim_i
pairwise coprime moduli
xx
solution

Example

Solve x≡2 (mod 3)x\equiv2\ (\mathrm{mod}\ 3), x≡3 (mod 5)x\equiv3\ (\mathrm{mod}\ 5), x≡2 (mod 7)x\equiv2\ (\mathrm{mod}\ 7).

  1. x≡2(mod21)x\equiv2\pmod{21} from the first and third: x=2,23,44,…x=2,23,44,\ldots
  2. 23≡3(mod5)23\equiv3\pmod5.

Answer: x≡23(mod105)x\equiv23\pmod{105}.

Related formulas