Sunteți pe pagina 1din 8

7.

Chinese Remainder Theorem


Dr. Min Ru, University of Houston

1 Theory
Accoding 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, by 7 the remainder is 2. What will
be the number?

Problem of this kind are examples of what universally became known as the Chi-
nese Remainder Theorem. In mathematical parlance the problems can be stated as
finding integer x such that
x ≡ a1 (mod m1 )
···
x ≡ ak (mod mk ).

We have discussed the case when k = 1 in chapter 5 (solving linear congruence


ax ≡ b (mod n)). Please review the steps of solving the linear congruences ax ≡ b
(mod n). Recall the main result in chapter 5 as as follows: The linear congruence
ax ≡ b (mod n) has a solution if and only if d|b where d =gcd(a, n). If d|b, then it
has d mutually incongruent solutions modulo n. In particular, if gcd(a, n)=1, then
the linear congruence ax ≡ b (mod n) has a unique solution modulo n.

This chapter studies the case when k ≥ 2 (the system of linear congruences). We
first discuss the case when k = 2, i.e. we solve a system of linear congruences linear
congruences
a1 x ≡ b1 (mod m1 )
a2 x ≡ b2 (mod m2 ).

1
We shall assume, for simplicity, that gcd(m1 , m2 ) = 1 (i.e. m1 , m2 are relatively
prime in pairs). Evidently, the system will admit no solutions unless each individial
congruence is solvable; that is, unless d1 |b1 and d2 |b2 , where d1 =gcd(a1 , m1 ) and
d2 =gcd(a2 , m2 ). Write a1 = d1 a01 , m1 = d1 n1 , b1 = d1 b01 a2 = d2 a02 , b2 = d1 b02 , m2 =
d2 n2 , the system above is equivalent to the new system

a01 x ≡ b01 (mod n1 )

a02 x ≡ b02 (mod n2 )


with the additional condition that gcd(a01 , m01 ) = 1, gcd(a02 , m02 ) = 1. By taking the
multiplicative inverses of a01 mod n1 and of a02 mod n2 respectively, we reduce it to
the form
x ≡ c1 (mod n1 )
x ≡ c2 (mod n2 ).
Thus the problem is reduced to find a simultaneous solution of a system
of the congruences of this simple type:

x ≡ a1 (mod m1 )

···
x ≡ ak (mod mk ).

In the case when k = 2, we have the following theorem.

Theorem(see Theorem 7.2 on Chapter summary) The pair of congruences

x ≡ a1 (mod m1 ) and x ≡ a2 (mod m2 )

has solution if and only if a1 ≡ a2 (mod gcd(m1 , m2 )). In the cases where a solution
x0 exists, all solutions are of the form x = x0 + nlcm(m1 , m2 ) for some n (in other
words, the solution is unique modulo lcm(m1 , m2 )), where lcm(m1 , m2 ) is the least
common multiple.

For example, the pair of congruences x ≡ 3 (mod 2), x ≡ 0 (mod 4) has no


solution since 3 6≡ 0 (mod 2).

The proof of the above theorem can be found on P. 368 in the Chapter summary
(chapter 7). Here I just want to convice you that a1 ≡ a2 (mod gcd(m1 , m2 )) is
necessary for the existence of a solution: assume that there is an integer x0 with

2
x0 ≡ a1 (mod m1 ) and x0 ≡ a2 (mod m2 ). This means that x0 = a1 + k1 m1 , x0 =
a2 = k2 m2 . Hence a1 + k1 m1 = a2 + k2 m2 , i.e. a2 − a2 = k2 m2 + k2 m1 . Now since
gcd(m1 , m2 )|m1 and gcd(m1 , m2 )|m2 , we get gcd(m1 , m2 )|(a2 − a1 ), i.e. a1 ≡ a2 (mod
gcd(m1 , m2 )). To see why a1 ≡ a2 (mod gcd(m1 , m2 )) gurantees the existence of such
x0 , please read the proof of the above theorem which can be found on P. 368 in the
Chapter summary (chapter 7).
A special case of the above theorem is when gcd(m1 , m2 )=1, i.e. m1 , m2 are
relatively prime in pairs. In this case, a1 ≡ a2 (mod gcd(m1 , m2 ) = 1) always
holds, so we have
Theorem(see Theorem 7.1 on Chapter summary) If m1 , m2 are positive integers such
that gcd(m1 , m2 )=1. Then for any integers a1 , a2 , the system of linear congruences
x ≡ a1 (mod m1 ) and x ≡ a2 (mod m2 )
has a unique solution modulo m1 m2 .
For example, the pair of congruences x ≡ 2 (mod 3), x ≡ 3 (mod 5) has a unique
solution x ≡ 8 (mod 15).
By Theorem 7.4 in chapter summary, the above unique solution modulo m1 m2
is given by the following explicit formula (which you can use to solve the pair of
congruences).
Explicit Formula: If m1 and m2 are positive integers such that gcd(m1 , m2 ) = 1. Let
m01 (resp. m02 ) be the multiplicative inverse of m1 modulo m2 (resp. the multiplicative
inverse of m2 modulo m1 ). Then
x0 = m01 a2 m1 + m02 a1 m2 (∗)
is a solution to the pair of congruences x ≡ a1 (mod m1 ) and x ≡ a2 (mod m2 )
The above explicit formula told us, assuming gcd(m1 , m2 ) = 1, to solve the pair
of congruences, you only need to find the m01 (which is the multiplicative inverse of
m1 modulo m2 ), and m02 (which is the multiplicative inverse of m2 modulo m1 ). So
we now have at least TWO methods of solving the pair of congruences.
From the theorem (Theorem 7.2), we can see the
Method of solving the pair of linear congruences is:
Step 1: check whether a1 ≡ a2 (mod gcd(m1 , m2 )). If so, then there are solutions;
Step 2: All solutions are of the form x ≡ x0 (mod lcm(m1 , m2 )) where x0 is a(any)
particular solution (so it gets down to find a particular solution x0 ).

3
2 Examples of solving pair of congruences
Example 1. Solve x ≡ 59 (mod 60), x ≡ 35 (mod 42).

Solution: The most naive way or idea is to multiply some numbers to the first AND
second equation (in modulus as well) to get a common modulo which is lcm(m1 , m2 ).
Note that lcm(60, 42)=420, so we need to multiply 7 to the first equation x ≡ 59
(mod 60) and multiply 10 to the second equation x ≡ 35 (mod 42). Hence we get
7x ≡ 413 (mod 420) and 10x ≡ 350 (mod 420) (note the purpose of doing so is to
get a common modulo). We then subtract the first new equation from the second
new equation to get 3x ≡ −63 ≡ 357 (mod 420). By using the method discussed in
section 2, we solve 3x ≡ 357 (mod 420) to get our solution x ≡ 119 (mod 420) and
x ≡ 259 (mod 420) (warning: since gcd(3, 420)=2, you NEED TWO solutions. DO
NOT LOSS ANY SOLUTIONS!).

Other methods in solving the SYSTEM of Linear Congruence Equations x ≡ a1


(mod m1 ) and x ≡ a2 (mod m2 ) include reducing it to solving linear Diophantine
equation and By using the explicit formula(warning: if you want to use the explicit
formula, you need to MAKE SURE that gcd(m1 , m2 ) = 1). The following examples
discuss these methods.

Example 2. Solve the pair of congruences

x ≡ 3 (mod 4) and x ≡ 5 (mod 6).

Solution:

Step 1: Since gcd(4, 6)=2, and 3 ≡ 5 (mod 2), so solutions exist. We find lcm(4, 6),
the least common multiple of 4 and 6 (i.e. the smallest integer k such that 4|k and
6|k). Clearly lcm(4, 6)=12. So according to the theorem, the solution is of the form
x ≡ x0 (mod 12).

Step 2: According to the above, we need to find x0 , a particular solution, i.e. x ≡ x0


(mod 12).

To find x0 , we propose Two methods (may be more).

Method 1 (reduce to chapter 5 about solving a single congruence):

The idea is to get the common modulo. Note that the first equation has modulo 4,
while the second equation has modulo 6. So the common is lcm(4, 6)=12. To do so,

4
it is obvious that we need to multiply 3 to the first equation. and multiply 2 to the
second equation. Thus we get

3x ≡ 9 (mod 12) and 2x ≡ 10 (mod 12).

Subtracting the second equation from the first equation, one obtains x ≡ −1 ≡ 11
(mod 12). Not that here we obtained the result directly. In general, we may need to
use the method we learned from chapter 5 about solving linear congruence to solve
the new single linear congruence.

Method 2 (reduce to solving linear Diophantine equation in chapter 2):

The idea of this method is (as we did in Chapter 5 of solving the linear congruence)
to convert the congruence to linear Diophantine equation and then solve the linear
Diophantine equation by using the reverse Euclidean method.

The following are the steps of getting x0 .

1. Starting from the first equation x ≡ 3 (mod 4), we get x = 3 + 4k1 for some
integer k (to be determined).

2. From the second equation x ≡ 5 (mod 6), we get x = 5 + 6k2 some integer k2
(to be determined).

3. Comparing 1 and 2, we get the linear Diophantine equation 3 + 4k1 = 5 + 6k2 ,


or 4k1 − 6k2 = 2, or 2k1 − 3k2 = 1 Solving this linear Diophantine equation by using
the reverse Euclidean method (or we can see it directly) to get k1 = 2, k2 = 1.

4. Substitute it back to x to get x0 = 3 + 8 = 11.

5. In conclusion, the solution to the above pair of congruences is x ≡ 11 (mod


12).

Example 3. Solve the pair of congruences

x ≡ 2 (mod 3) and x ≡ 3 (mod 5).

Solution: Since gcd(3, 5)=1, according to the theorem, the solution is of the form
x ≡ x0 (mod 15). To find x0 , we propose THREE methods (note that because gcd(3,
5)=1, we can use the explicit formula (*) stated in the theorem above).

Method 1 (reduce to chapter 5 about solving a single congruence):

5
The idea is to get the common modulo. Here is the common modulo is 15. By
multiplying 5 to the first equation and multiply 3 to the second equation, one gets
5x ≡ 10 (mod 15) and 3x ≡ 9 (mod 15).
Subtracting the second equation from the first yields 2x ≡ 1 (mod 15). Using the
method in chapter 5 (or in this case, you can directly see it), one gets x ≡ 8 (mod
15).

Method 2 (reduce to solving linear Diophantine equation in chapter 2):

The following are the steps of getting x0 in this method.

1. Starting from x ≡ 2 (mod 3), we get x = 2 + 3k1 for some integer k1 (to be
determined).

2. From the second equation x ≡ 3 (mod 5), x = 3 + 5k2 some integer k2 (to be
determined).

3. Combining 1 and 2 to get 2+3k1 = 3+5k2 , or 3k1 −5k2 = 1. Solving this linear
Diophantine equation by using the reverse Euclidean method to getk1 = 2, k2 = 1
(here we can indeed see the solution directly).

4. Substitute it back to x to get x0 = 2 + 3k1 = 8.

5. In conclusion, the solution to the above pair of congruences is x ≡ 8 (mod 15).

Method 3 (using the explicit formula): We use the above Explicit Formula with
m1 = 3, m2 = 5 (since gcd(3, 5)=1), a1 = 2, a2 = 3. To do so, we need find m01 which
is the multiplicative inverse of m1 = 3 modulo m2 = 5, as well as m02 which is the
multiplicative inverse of m2 = 5 modulo m1 = 3.
We first find m01 , the multiplicative inverse of 3 modulo 5, i.e. 3m01 ≡ 1 (mod 5).
By solving it (see Problem 1 in HW#5 on how to find the multiplicative inverse), we
get m01 ≡ 2 (mod 5). Similarly, we can get m02 ≡ 2 (mod 3) by solving 5m02 ≡ 1 (mod
3). Hence, by the formula (*) in the above Explicit Formula, with m1 = 3, m2 =
5, m01 = 2, m02 = 2, a1 = 2, a2 = 3,
x0 = m01 a2 m1 + m02 a1 m2 = 2 + 2 × 2 × 5 = 38
is a solution. So x = 38 ≡ 8 (mod 15) is the general solution to the above pair of
congruences.

I hope by now you should know how to solve the pair of congruences.

6
3 Solving Lots (more than 2) of Congruences
Chinese Remainder Theorem: Suppose that the positive integers m1 , . . . , mn are
pairwise relatively prime. Then for any integers a1 , . . . , an , the set of congruences
x ≡ a1 (mod m1 ), . . . , x ≡ an (mod mn ) has a unique solution modulo m1 m2 . . . mn .

Example 1(system of three equations): Solve x ≡ 0 (mod 3), x ≡ 2 (mod 5),


x ≡ 6 (mod 11).

Solution. We use the method appeared in the examples above about solving pair of
congruences (three methods). The idea is to first solve the two equations (usually we
take the first two) as a pair to get a new single equation, then solve the new equation
together with the leftover (the third) equation as a new pair. In doing so, we divide
it into two steps.

Step 1: We solve the first pair of congruences x ≡ 0 (mod 3), x ≡ 2 (mod 5) to


get the new equation x ≡ 12 (mod 15) (Remark: See examples of solving pairs of
congruences above. There are at least three methods of doing so).

Step 2: Next we solve this new equation x ≡ 12 (mod 15) together with the last
equation x ≡ 6 (mod 11). i.e. x ≡ 72 mod (165)), i.e.

x ≡ 12 (mod 15) and x ≡ 6 (mod 11).

Similar to the examples above (three methods), we get x ≡ 72 mod (165) (note that
3, 5, and 11 are pairwise relatively prime, and 3 × 5 × 11 = 165).

Example 2 (system of four equations): Solve x ≡ 3 (mod 4), x ≡ 4 (mod 7),


x ≡ 1 (mod 9), x ≡ 0 (mod 11).

Solution. The idea is to solve the two equations (a pair) each time. We usually take
the first two as a pair to get a new single equation, and the last two as another pair
to get another new single equation. We then solve the two new equations as a pair.
In doing so, we divide it into three steps.

Step 1: We solve the first pair of congruences x ≡ 3 (mod 4), x ≡ 4 (mod 7) to get
the new equation x ≡ 11 (mod 28) (Remark: There are at least three methods of
doing so as shown in the example above).

Step 2: We solve the second pair of congruences (the third and forth equations) x ≡ 1
(mod 9), x ≡ 0 (mod 11) to get another new equation x ≡ 44 (mod 99) (Remark:
There are at least three methods of doing so as shown in the example above).

7
Step 3: We solve the two new equations obtained above as a pair, i.e. x ≡ 11 (mod
28), x ≡ 44 (mod 99). We get x ≡ 1243 (mod 2772) (note that 4, 7, 9 and 11 are
pairwise relatively prime, and 4 × 7 × 9 × 11 = 2772).

Remark: This book only dealt with the case when the positive integers m1 , . . . , mn
are pairwise relatively prime. The general case was not considered.

S-ar putea să vă placă și