Chinese Remainder Theorem
According to D. Wells, the following problem was posed by Sun Tsu Suan-Ching (4th century AD):
There are certain things whose number is unknown. Repeatedly divided by 3, the remainder is 2; by 5 the remainder is 3; and by 7 the remainder is 2. What will be the number?
Oystein Ore mentions another puzzle with a dramatic element from
Brahma-Sphuta-Siddhanta
(Brahma's Correct System) by Brahmagupta (born 598 AD):
An old woman goes to market and a horse steps on her basket and crashes
the eggs. The rider offers to pay for the damages and asks her how many
eggs she had brought. She does not remember the exact number, but when
she had taken them out two at a time, there was one egg left. The same
happened when she picked them out three, four, five, and six at a time,
but when she took them seven at a time they came out even. What is the
smallest number of eggs she could have had?
Problems of this kind are all examples of what universally became known as the
Chinese Remainder Theorem. In mathematical parlance the problems can be stated as finding n, given its remainders of division by several numbers
m1,m2,…,mk:
(1)
nnn=n1 (modm1)=n2 (modm2) …=nk (modmk)
The modern day theorem is best stated with a couple of useful notations. For non-negative integers
m1,m2,…,mk, their
greatest common divisor is defined as
gcd(m1,m2,…,mk)=max{s:s|mi, for i=1,…,k},
where, as always,
s|m means that
s divides
m exactly. The
least common multiple of
k numbers is defined as
lcm(m1,m2,…,mk)=min{s:s>0 and mi|s, for i=1,…,k},
Both
gcd() and
lcm() are symmetric functions of their arguments. They are complementary in the sense that, for
k=2,
gcd(m1,m2)⋅lcm(m1,m2)=m1⋅m2.
(A proof and an interactive illustration for this identity appears
elsewhere.)
However, for
k>2 a similar identity does not in general hold. For an example, consider two triplets:
{2,4,16} and
{2,8,16}. Both have exactly the same
gcd and
lcm but obviously different products. On the other hand, both
gcd and
lcm are
associative:
gcd(m1, (gcd(m2,m3))=gcd(gcd(m1,m2),m3)
and, both equal
gcd(m1,m2,m3). Similarly,
lcm(m1, (lcm(m2,m3))=lcm(lcm(m1,m2),m3).
Note
If, for a prime
p, pαi|mi, with
αi being the largest exponent with that property, then
pα|lcm(m1,m2,…,mk), where
α=max{αi} and
α
is the largest exponent with that property. Similarly, the greatest
common divisor of several numbers is the product of the largest powers
of the primes that divide all the given numbers.
Associativity allows one to proceed a step at a time with an
inductive argument without putting all eggs into a basket at once.
Jumping at the opportunity I'll prove the most basic case of
k=2.
Theorem 1
Two simultaneous congruences
nn=n1 (mod m1) and=n2 (mod m2)
are only solvable when
n1=n2 (mod gcd(m1,m2)). The solution
is unique modulo
lcm(m1,m2).
(When
m1 and
m2 are coprime their
gcd is
1. By convention,
a=b (mod 1) holds for any
a and
b.)
Proof
By a
generalization of Euclid's algorithm, there are integers s and t such that
tm1+sm2=gcd(m1,m2).
Since n2−n1=0 (mod gcd(m1,m2)), for some, possibly different t and s,
(2)
tm1+sm2=n2−n1.
Then
n=tm1+n1=−sm2+n2 satisfies both congruences in the theorem. This proves the existence of a solution.
To prove the uniqueness part, assume
n and
N satisfy the two congruences. Taking the differences we see that
N−n=0 (mod m1) and N−n=0 (modm2)
which implies
N−n=0 (mod lcm(m1,m2)).
As was previously stated, a more general theorem can now be proved by
induction.
Theorem 2
The simultaneous congruences
(1)
nnn=n1=n2 …=nk(modm1)(modm2)(modmk)
are only solvable when
ni=nj (mod gcd(mi,mj)), for all
i and
j, i≠j. The solution
is unique modulo
lcm(m1,m2,…,mk).
Proof
Theorem 1 serves the initial step verification. Assume the theorem holds for
k congruences and consider
k+1 of them.
nnnn=n1=n2 …=nk=nk+1(mod m1)(mod m2)(mod mk)(mod mk+1)
Let
s be a solution to the first
k equations. Then the congrurence
n=s (mod lcm(m1,m2,…,mk)) has a solution. (Observe that every solution of the latter also satisfies the first
k congruences.) To be able to apply the already proven Theorem 1, we need to show that
(3)
s=nk+1 (mod gcd(lcm(m1,…,mk),mk+1)).
Let's write
gu=gcd(mu,mk+1),u=1,…,k. Then we know that
nu=nk+1 (mod gu) for these values of
u. But
nu=s+tumu, for some
tu, implying
nk+1=s+tumu (mod gu) so that
s=nk+1 (mod gu), u=1,2,…,k.
If so,
s=nk+1 (mod lcm(g1,…,gk))=nk+1 (mod lcm(gcd(m1,mk+1),…,gcd(mk,mk+1)))=nk+1 (mod gcd(lcm(m1,…,mk),mk+1)),
because lcm(gcd(m1,mk+1),…,gcd(mk,mk+1))=gcd(lcm(m1,…,mk),mk+1).
Thus the system
nn=s (mod lcm(m1,m2,…,mk))=nk+1 (mod mk+1)
has a solution which is unique modulo
lcm(lcm(m1,m2,…,mk),mk+1)=lcm(m1,m2,…,mk,mk+1).
It also satisfies the whole set of
k+1 congruences.
Corollary
The simultaneous congruences
(1)
nnn=n1 (mod m1)=n2 (mod m2) …=nk (mod mk)
where all
mi's are pairwise coprime has a unique solution modulo
m1⋅m2⋅…⋅mk.
If some
mi's are not mutually prime, a solution may not exist unless the corresponding congruence agree. For example, the system
n=1 (mod 2) and
n=2 (mod 4) has not solution, while the system
n=1 (mod 2) and
n=±1 (mod 4) does.

Let's now solve the two problems we started the page with.
Problem #1
Solve
⎧⎩⎨p1:p2:p3:x=2 (mod 3)x=3 (mod 5)x=2 (mod 7)
From
p1,
x=3t+2, for some integer
t. Substituting this into
p2 gives
3t=1 (mod 5). Looking
up
1/3 in the
division table modulo
5, this reduces to a simpler equation
p4: t=2 (mod 5)
which, in turn, is equivalent to
t=5s+2 for an integer
s. Substitution into
x=3t+2
yields
x=15s+8. This now goes into
p3:15s+8=2 (mod 7). Casting out 7 gives
s=1 (mod 7). From here,
s=7u+1 and, finally,
x=105u+23.
Note that
105=lcm(3,5,7). Thus we have solutions
23,128,233,…
Problem #2
Solve
⎧⎩⎨⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪⎪q1:q2:q3:q4:q5:q6:x=1 (mod 2)x=1 (mod 3)x=1 (mod 4)x=1 (mod 5)x=1 (mod 6)x=0 (mod 7)
With the experience we acquired so far, the combination of
q1−q5 is equivalent to
q7: x=1 (mod 60),
x=60t+1. Plugging this into
q6 gives
60t=−1 (mod 7). Casting out 7 simplifies this to
4t=6 (mod 7) and then
2t=3 (mod 7). From the
division tables modulo
7, 3/2=5 (mod 7). Therefore,
t=7u+5. Finally,
x=420u+301. Allowing for an average size farmer, the most likely number of eggs she might expect to be compensated for is
301.
Note: The Chinese Remainder Theorem finds an important
application in the clendrical calculations.
References
- H. Davenport, The Higher Arithmetic, Cambridge University Press; 7 edition (December 9, 1999)
- P. J. Davis and R. Hersh, The Mathematical Experience, Houghton Mifflin Company, Boston, 1981
- U. Dudley, Elementary Number Theory, Dover, 2008
- R. Graham, D. Knuth, O. Patashnik, Concrete Mathematics, 2nd edition, Addison-Wesley, 1994.
- Oystein Ore, Number Theory and Its History, Dover Publications, 1976
- D. Wells, The Penguin Book of Curious and Interesting Puzzles, Penguin Books, 1992
Posting Komentar