]> Number Theory - The Chinese Remainder Theorem

The Chinese Remainder Theorem

Suppose we are asked to solve

x=2 (mod5 ) x=3 (mod7 )

for x. Notice if we have a solution y, then y+35 is also a solution, and in fact so is y plus any mulitple of 35 . So we only need to look for solutions modulo 35 . By brute force, we find the only solution is x=17 (mod35 ).

For any system of equations like this, the Chinese Remainder Theorem not only tells us that there is a solution, but also that it is unique. Additonally, the theorem describes how to find the solution efficiently.

Theorem: Let p,q be coprime. Then the system of equations

x=a(modp) x=b(modq)

has a unique solution for x modulo pq.

The reverse direction is trivial: given x pq, we can reduce x modulo p and x modulo q to obtain two equations of the above form.

Proof: Let p 1 =p 1 (modq) and q 1 =q 1 (modp). These must exist since p,q are coprime. Then we claim that if y is an integer such that

y=aqq 1 +bpp 1 (modpq)

then y satisfies both equations:

Modulo p, we have y=aqq 1 =a(modp) since qq 1 =1 (modp). Similarly y=b(modq). Thus y is a solution for x.

It remains to show no other solutions exist modulo pq. If z=a(modp) then zy is a multiple of p. If z=b(modq) as well, then zy is also a multiple of q. Since p and q are coprime, this implies zy is a multiple of pq, hence z=y(modpq).

This theorem implies we can represent an element of pq by one element of p and one element of q, and vice versa. In other words, we have a bijection between pq and p× q.

Examples: We can write 17 35 as (2,3 ) 5 × 7 . We can write 1 pq as (1,1 ) p× q.

In fact, this correspondence goes further than a simple relabelling. Suppose x,y pq correspond to (a,b),(c,d) p× q respectively. Then a little thought shows x+y corresponds to (a+c,b+d), and similarly xy corresponds to (ac,bd).

A practical application: if we have many computations to perform on x pq (e.g. RSA signing and decryption), we can convert x to (a,b) p× q and do all the computations on a and b instead before converting back. This is often cheaper because for many algorithms, doubling the size of the input more than doubles the running time.

Example: To compute 17 ×17 (mod35 ), we can compute (2 ×2,3 ×3 )=(4,2 ) in 5 × 7 , and then apply the Chinese Remainder Theorem to find that (4,2 ) is 9 (mod35 ).

Let us restate the Chinese Remainder Theorem in the form it is usually presented.

For Several Equations

Theorem: Let m 1 ,...,m n be pairwise coprime (that is gcd(m i,m j)=1 whenever ij). Then the system of n equations

x=a 1 (modm 1 ) ... x=a n(modm n)

has a unique solution for x modulo M where M=m 1 ...m n.

Proof: This is an easy induction from the previous form of the theorem, or we can write down the solution directly.

Define b i=M/m i (the product of all the moduli except for m i) and b i=b i 1 (modm i). Then by a similar argument to before,

x= i=1 na ib ib i(modM)

is the unique solution.

Prime Powers First

An important consequence of the theorem is that when studying modular arithmetic in general, we can first study modular arithmetic a prime power and then appeal to the Chinese Remainder Theorem to generalize any results. For any integer n, we factorize n into primes n=p 1 k 1 ...p m k m and then use the Chinese Remainder Theorem to get

n= p 1 k 1 ×...× p m k m

To prove statements in p k, one starts from p, and inductively works up to p k. Thus the most important case to study is p.