THE CHINESE REMAINDER THEOREM KEITH CONRAD We should thank the Chnese for ther wonderful remander theorem. Glenn Stevens 1. Introducton The Chnese remander theorem says we can unquely solve any par of congruences that have relatvely prme modul. Theorem 1.1. Let m and n be relatvely prme postve ntegers. For any ntegers a and b, the par of congruences x a mod m, x b mod n has a soluton, and ths soluton s unquely determned modulo mn. What s mportant here s that m and n are relatvely prme. There are no constrants at all on a and b. Example 1.2. The congruences x 6 mod 9 and x 4 mod 11 hold when x = 15, and more generally when x 15 mod 99, and they do not hold for any other x. The modulus 99 s 9 11. We wll prove the Chnese remander theorem, ncludng a verson for more than two modul, and see some ways t s appled to count solutons of congruences. 2. A proof of the Chnese remander theorem Proof. Frst we show there s always a soluton. Then we wll show t s unque modulo mn. Exstence of Soluton. To show that the smultaneous congruences x a mod m, x b mod n have a common soluton n Z, we gve two proofs. Frst proof: Wrte the frst congruence as an equaton n Z, say x = a + my for some y Z. Then the second congruence s the same as a + my b mod n. Subtractng a from both sdes, we need to solve for y n (2.1) my b a mod n. Snce (m, n) = 1, we know m mod n s nvertble. Let m be an nverse for m mod n, so mm 1 mod n. Multplyng through (2.1) by m, we have y m (b a) mod n, so y m (b a) + nz where z Z. Then x = a + my = a + m(m (b a) + nz) = a + mm (b a) + mnz. 1
2 KEITH CONRAD So f x satsfes the orgnal two congruences t must have ths form. Let s now check ths expresson, for every z Z, really satsfes the orgnal two congruences: a + mm (b a) + mnz a + 0 + 0 a mod m and a + mm (b a) + mnz a + 1(b a) + 0 b mod n. Second proof: Wrte both congruences as equatons n Z: x = a + my and x = b + nz for ntegers y and z that need to be determned. (Why would t be a bad dea to wrte x = a + my and x = b + ny?) The ntegers of the form a + my are the numbers that are congruent to a mod m, and the ntegers of the form b + nz are the numbers that are congruent to b mod n. Fndng a common soluton to the two congruences amounts to fndng y and z n Z such that a + my = b + nz, whch s the same as (2.2) my nz = b a. Can we fnd such y and z for any a, b, m, and n where (m, n) = 1? Bezout s dentty tells us 1 s a Z-lnear combnaton of m and n, and therefore any nteger s Z-lnear combnaton of m and n (why?). Therefore ntegers y and z satsfyng (2.2) exst. Unqueness of Soluton. If x = c and x = c both satsfy x a mod m, x b mod n, then we have c c mod m and c c mod n. Then m (c c ) and n (c c ). Snce (m, n) = 1, the product mn dvdes c c, whch means c c mod mn. Ths shows any two solutons to the ntal par of congruences are the same modulo mn. 3. Extenson to more than two congruences The Chnese remander theorem can be extended from two congruences to any fnte number of congruences, but we have to be careful about the way n whch the modul are relatvely prme. Consder the three congruences x 1 mod 6, x 4 mod 10, x 7 mod 15. Whle there s no common factor of 6, 10, and 15 greater than 1, these congruences do not admt a common soluton: any soluton to the frst congruence s odd, whle any soluton to the second congruence s even. When we have more than two modul, we have to be senstve to the dfference between sayng numbers are collectvely relatvely prme (no common factor greater than 1 dvdes them all) and parwse relatvely prme (no common factor greater than 1 dvdes any two of the numbers). For nstance, 6, 10, and 15 are collectvely relatvely prme but not parwse relatvely prme. Here s a more general form of the Chnese remander theorem. Theorem 3.1. For r 2, let m 1, m 2,..., m r be nonzero ntegers that are parwse relatvely prme: (m, m j ) = 1 for j. Then, for any ntegers a 1, a 2,..., a r, the system of congruences x a 1 mod m 1, x a 2 mod m 2,..., x a r mod m r, has a soluton, and ths soluton s unquely determned modulo m 1 m 2 m r. Example 3.2. The congruences x 1 mod 3, x 2 mod 5, x 2 mod 7 are satsfed when x = 37, more generally for any x 37 mod 105 and for no other x. Note 105 = 3 5 7.
THE CHINESE REMAINDER THEOREM 3 Proof. Frst we show there s always a soluton. Then we wll show t s unque modulo m 1 m 2 m r. Exstence of Soluton. We argue by nducton on r. The base case r = 2 s Theorem 1.1, whch has been proved already. Now we pass to the nductve step. Suppose all smultaneous congruences wth r parwse relatvely prme modul can be solved. Consder a system of smultaneous congruences wth r + 1 parwse relatvely prme modul: x a 1 mod m 1,..., x a r mod m r, x a r+1 mod m r+1, where (m, m j ) = 1 for all j and the a s are arbtrary. By the nductve hypothess, there s a soluton b to the frst r congruences, say b a 1 mod m 1, b a 2 mod m 2,..., b a r mod m r. Now consder the system of two congruences (3.1) x b mod m 1 m 2 m r, x a r+1 mod m r+1. Snce (m, m r+1 ) = 1 for = 1, 2,..., r, we have (m 1 m 2 m r, m r+1 ) = 1, so the two modul n (3.1) are relatvely prme. Then by the case of two congruences, namely Theorem 1.1, there s a soluton to (3.1). Call t c. Snce c b mod m 1 m 2 m r, we have c b mod m for = 1, 2,..., r. From the choce of b we have b a mod m for = 1, 2,..., r. Therefore c a mod m for = 1, 2,..., r. Also, c a r+1 mod m r+1 from the choce of c, so we see c satsfes the r + 1 gven congruences. Ths concludes the nductve step, so a soluton exsts. Unqueness of Soluton. If x = c and x = c both satsfy x a 1 mod m 1, x a 2 mod m 2,..., x a r mod m r, then we have c c mod m for = 1, 2,..., r, so m (c c ) for = 1, 2,..., r. Snce the m s are parwse relatvely prme, ther product m 1 m 2 m r dvdes c c, whch means c c mod m 1 m 2 m r. Ths shows any two solutons to the gven system of congruences are the same when vewed modulo m 1 m 2 m r. 4. Applcatons The sgnfcance of the Chnese remander theorem s that t often reduces a queston about modulus mn, where (m, n) = 1, to the same queston for modulus m and n separately. In ths way, questons about modular arthmetc can often be reduced to the specal case of prme power modul. We wll see how ths works for several countng problems, often usng two features of modular arthmetc wth two modul: f d m t makes sense to reduce ntegers mod m to ntegers mod d: f x y mod m then x y mod d. For example, f x y mod 10 then x y mod 5 snce f x y s dvsble by 10 then t s also dvsble by 5. (In contrast, t makes no sense to reduce x mod 10 to x mod 3, snce there are congruent numbers mod 10 that are ncongruent mod 3, such as 5 and 15.) f x y mod m and x y mod n and (m, n) = 1 then x y mod mn. Ths was used n the unqueness part of the proof of the Chnese remander theorem. Our frst applcaton s to countng unts. Theorem 4.1. For relatvely prme postve ntegers m and n, ϕ(mn) = ϕ(m)ϕ(n).
4 KEITH CONRAD Proof. We work wth the sets U m = {a mod m, (a, m) = 1}, U n = {b mod n, (b, n) = 1}, U mn = {c mod mn, (c, mn) = 1}. Then U m = ϕ(m), U n = ϕ(n), and U mn = ϕ(mn). To show ϕ(mn) = ϕ(m)ϕ(n), we wll wrte down a bjecton between U mn and U m U n, whch mples the two sets have the same sze, and that s what the theorem s sayng (snce U m U n = ϕ(m)ϕ(n)). Let f : U mn U m U n by the rule f(c mod mn) = (c mod m, c mod n). For c U mn, we have (c, mn) = 1, so (c, m) and (c, n) equal 1, so c mod m and c mod n are unts. Let s stop for a moment to take a look at an example of ths functon. Take m = 3 and n = 5: U 3 = {1, 2}, U 5 = {1, 2, 3, 4}, and U 15 = {1, 2, 4, 7, 8, 11, 13, 14}. The followng table shows the values of the functon f on each number n U 15. Notce that the values fll up all of U 3 U 5 wthout repetton. c mod 15 f(c mod 15) 1 (1, 1) 2 (2, 2) 4 (4, 4) = (1, 4) 7 (7, 7) = (1, 2) 8 (8, 8) = (2, 3) 11 (11, 11) = (2, 1) 13 (13, 13) = (1, 3) 14 (14, 14) = (2, 4) There are 2 unts modulo 3 and 4 unts modulo 5, leadng to 8 ordered pars of unts modulo 3 and unts modulo 5: (1,1), (1,2), (1,3), (1,4), (2,1), (2,2), (2,3), and (2,4). All these pars show up (and just once) n the second column of the table. We return to the general stuaton and show f : U mn U m U n s a bjecton. To see that f s one-to-one, suppose f(k mod m) = f(l mod n) Then k l mod m and k l mod n, so snce (m, n) = 1 (aha!), we have k l mod mn. That means k = l n U mn, so f s one-to-one. Now we show f s onto. Pck any par (a mod m, b mod n) U m U n. By the Chnese remander theorem we can solve c a mod m and c b mod n for a c Z. Is (c, mn) = 1? Snce a mod m s a unt and c a mod m, c mod m s a unt so (c, m) = 1. Snce b mod n s a unt and c b mod n, c mod n s a unt so (c, n) = 1. From (c, m) = 1 and (c, n) = 1 we get (c, mn) = 1, so c U mn. From the congruence condtons on c, we have f(c) = (a, b). Corollary 4.2. For a postve nteger m, ϕ(m) = m p m ( 1 1 ), p where the product runs over the prmes p dvdng m. Proof. The formula s clear for m = 1 (nterpretng an empty product as 1). Now suppose m > 1, and factor m nto prme powers: m = p e 1 1 pe 2 2 per r.
THE CHINESE REMAINDER THEOREM 5 The p e s are parwse relatvely prme. By an extenson of Theorem 4.1 from two relatvely prme terms to any number of parwse relatvely prme terms (just nduct on the number of terms), we have ϕ(m) = ϕ(p e 1 1 )ϕ(pe 2 2 ) ϕ(per r ). Now usng the formula for ϕ on prme powers, ϕ(m) = p e 1 1 1 (p 1 1)p e 2 1 2 (p 2 1) p er 1 r (p r 1) ) ) ) = p e 1 1 (1 1p1 p e 2 2 (1 1p2 p er r (1 1pr = m p m ( 1 1 p ). Example 4.3. To compute ϕ(540) = ϕ(2 2 3 3 5), we have ( ϕ(540) = 540 1 1 ) ( 1 1 ) ( 1 1 ) 2 3 5 An alternate calculaton s = 540 1 2 2 3 4 5 = 18 8 = 144. ϕ(540) = ϕ(4)ϕ(27)ϕ(5) = (4 2)(27 9)(5 1) = 2 18 4 = 144. We now leave unts mod m and look at squares mod m. Theorem 4.4. For m Z + wth m 2, let S m = {x 2 mod m} be the set of squares modulo m. When (m, n) = 1, S mn = S m S n. Note S m s all squares modulo m, ncludng 0. So S 5 = {0, 1, 4}, for example. Proof. We wll use the Chnese remander theorem twce. If a x 2 mod mn then a x 2 mod m and a x 2 mod n. Thus any square modulo mn reduces to a square modulo m and a square modulo n. So we have a functon f : S mn S m S n by f(a mod mn) = (a mod m, a mod n). Let s take a look at an example. Set m = 3 and n = 5, so S 3 = {0, 1}, S 5 = {0, 1, 4} and S 15 = {0, 1, 4, 6, 9, 10}. The table below gves the values of f on S 15. The values fll up S 3 S 5 wthout repetton. c mod 15 f(c mod 15) 0 (0, 0) 1 (1, 1) 4 (4, 4) = (1, 4) 6 (6, 6) = (0, 1) 9 (9, 9) = (0, 4) 10 (10, 10) = (1, 0)
6 KEITH CONRAD Returnng to the general case, to show f s one-to-one let s suppose f(c mod mn) = f(c mod mn). Then c c mod m and c c mod n, so c c mod mn snce (m, n) = 1. To show f s onto, pck a par of squares b mod m and c mod n, say b y 2 mod m and c z 2 mod n. By the Chnese remander theorem, there s an nteger a satsfyng a b mod m, a c mod n. We want to say f(a) = (b, c), but s a mod mn a square? From the expressons for b mod m and c mod n as squares, a y 2 mod m and a z 2 mod n, but y and z are not related to each other. They certanly don t have to be the same nteger, so these two congruences on ther own don t tell us a mod mn s a square. Usng the Chnese remander theorem agan, however, there s x Z such that x y mod m, x z mod n, so x 2 y 2 mod m and x 2 z 2 mod n. Therefore a x 2 mod m and a x 2 mod n, so a x 2 mod mn, so a mod mn s n fact a square. Thus a S mn and f(a) = (b, c). Example 4.5. For a prme p, the number of nonzero squares mod p s (p 1)/2 and 0 s a square, so the total number of squares mod p s 1 + (p 1)/2 = (p + 1)/2. Thus S p = (p + 1)/2. So f n = p 1 p 2... p r s squarefree, S n = S p1 S pr = p 1+1 2 pr+1 2. If n = p e 1 1 per r, we have S n = S e p 1 S 1 p er, so a formula for S r pe when e > 1 (whch we don t gve here) would lead to a formula for S m n general. We turn now from countng all the squares mod m to countng how often somethng s a square mod m. Example 4.6. We can wrte 1 mod 15 as a square n four ways: 1 1 2 4 2 9 2 14 2 mod 15. Theorem 4.7. Let m Z + have prme factorzaton p e 1 1 per r. For any nteger a, the congruence x 2 a mod m s solvable f and only f the separate congruences x 2 a mod p e are solvable for = 1, 2,..., r. Furthermore, f the congruence x 2 a mod p e has N solutons, then the congruence x 2 a mod m has N 1 N 2 N r solutons. Example 4.8. The congruences x 2 1 mod 3 and x 2 1 mod 5 each have two solutons, so x 2 1 mod 15 has 2 2 = 4 solutons; we saw the four square roots of 1 mod 15 before the statement of Theorem 4.7. Proof. If x Z satsfes x 2 a mod m, then x 2 a mod p e for all. Conversely, suppose each of the congruences x 2 a mod p e has a soluton, say x 2 a mod p e for some ntegers x. Snce the p e s are parwse relatvely prme, the Chnese remander theorem tells us there s an x such that x x mod p e for all. Then x 2 x 2 mod pe for all, so x 2 a mod p e for all. Snce x 2 a s dvsble by each p e t s dvsble by m, so x 2 a mod m. To count the solutons modulo m, we agan use the Chnese remander theorem. Any choce of soluton x mod p e for each fts together n exactly one way to a number x mod m, and ths number wll satsfy x 2 a mod m. Therefore we can count solutons modulo m by countng solutons modulo each p e and multply the counts thanks to the ndependence of the choce of solutons for dfferent prmes.
THE CHINESE REMAINDER THEOREM 7 Example 4.9. To decde f 61 s a square modulo 75, we check whether 61 s a square modulo 3 and modulo 25. Snce 61 1 mod 3, t s a square modulo 3. Snce 61 11 6 2 mod 25, t s a square modulo 25. Therefore 63 s a square modulo 75. In fact, we can get a square root by solvng the congruences A soluton s x = 31, so 61 31 2 mod 75. x 1 mod 3, x 6 mod 25. If you scrutnze the proofs of Theorems 4.4 and 4.7 to see why t was mportant we were workng wth squares, you ll see that t really wasn t; the only thng that really matters s that squarng s a polynomal expresson. Wth ths n mnd, we get the followng generalzatons from squares to values of other polynomals. Theorem 4.10. Let f(x) be any polynomal wth nteger coeffcents. For a postve nteger m 2, let N f (m) = {f(x) mod m : 0 x m 1} be the number of values of f on dfferent ntegers mod m. If m has prme factorzaton m = p e 1 1 per r, we have N f (m) = N f (p e 1 1 ) N f (p er r ). Proof. Proceed as n the proof of Theorem 4.4, whch s the specal case f(x) = x 2. Theorem 4.11. Let f(x) be any polynomal wth nteger coeffcents. For a postve nteger m wth prme factorzaton m = p e 1 1 per r, the congruence f(x) 0 mod m s solvable f and only f the congruences f(x) 0 mod p e are each solvable. Moreover, f f(x) 0 mod p e has N solutons, then the congruence f(x) 0 mod m has N 1 N 2 N r solutons. Proof. Argue as n the proof of Theorem 4.7, whch s the specal case f(x) = x 2 a. Theorem 4.11 tells us that fndng solutons to a polynomal equaton modulo postve ntegers s reduced by the Chnese remander theorem to the case of understandng solutons modulo prme powers. Consder now the followng stuaton: f(x) s a polynomal wth ntegral coeffcents and every value f(n), for n Z, s ether a multple of 2 or a multple of 3. For nstance, f f(x) = x 2 x then f(n) = n 2 n s even for all n. Or f f(x) = x 3 x then f(n) = n 3 n s a multple of 3 for all n. But these examples are knd of weak: what about a mxed example where every f(n) s a multple of 2 or 3 but some f(n) are multples of 2 and not 3 whle other f(n) are multples of 3 and not 2? Actually, no such polynomal exsts! The only way f(n) can be dvsble ether by 2 or 3 for all n s f t s a multple of 2 for all n or a multple of 3 for all n. To explan ths, we wll use the Chnese remander theorem. Theorem 4.12. Let f(x) be a polynomal wth ntegral coeffcents. Suppose there s a fnte set of prmes p 1,..., p r such that, for every nteger n, f(n) s dvsble by some p. Then there s one p such that p f(n) for every n Z. Proof. Suppose the concluson s false. Then, for each p, there s an a Z such that p does not dvde f(a ). Sad dfferently, f(a ) 0 mod p. Snce the p s are dfferent prmes, we can use the Chnese remander theorem to fnd a sngle nteger a such that a a mod p for = 1, 2,..., r. Then f(a) f(a ) mod p for
8 KEITH CONRAD = 1, 2,..., r (why?), so f(a) 0 mod p for all. However, the assumpton n the theorem was that every value of the polynomal on ntegers s dvsble by some p, so we have a contradcton. Remark 4.13. It s natural to beleve an analogous result for dvsblty by squares of prmes. Specfcally, f f(x) s a polynomal wth ntegral coeffcents and there s a fnte set of prmes p 1,..., p r such that, for every nteger n, f(n) s dvsble by some p 2, then there should be one p such that p 2 f(n) for every n Z. If you try to adapt the proof of Theorem 4.12 to ths settng, t breaks down (where?). Whle ths analogue for dvsblty by squares of prmes s plausble, t s stll an open problem as far as I am aware. Our fnal applcaton of the Chnese remander theorem s to an nterpolaton problem. Gven n ponts n the plane, (a 1, b 1 ),..., (a n, b n ), wth the a s dstnct, we would lke to fnd a polynomal f(t ) n R[T ] whose graph passes through these ponts: f(a ) = b for = 1, 2,..., n. Ths task can be converted to a set of smultaneous congruences n R[T ], whch can be solved usng the Chnese remander theorem n R[T ], not Z. Frst let s state the Chnese remander theorem for polynomals. Theorem 4.14. For r 2, let m 1 (T ), m 2 (T ),..., m r (T ) be nonzero polynomals n R[T ] whch are parwse relatvely prme: (m (T ), m j (T )) = 1 for j. Then, for any polynomals a 1 (T ), a 2 (T ),..., a r (T ), the system of congruences f(t ) a 1 (T ) mod m 1 (T ), f(t ) a 2 (T ) mod m 2 (T ),..., f(t ) a r (T ) mod m r (T ), has a soluton f(t ) n R[T ], and ths soluton s unque modulo m 1 (T )m 2 (T ) m r (T ). The proof of ths s dentcal to that of the Chnese remander theorem for Z, so we leave t to the reader as an exercse. Theorem 4.15. In R, pck n dstnct numbers a 1, a 2,..., a n and any numbers b 1, b 2,..., b n. There s a unque polynomal f(t ) of degree < n n R[T ] such that f(a ) = b for all. Proof. To say f(a ) = b s the same as f(t ) b mod T a (why?). Consder the system of congruences f(t ) b 1 mod T a 1, f(t ) b 2 mod T a 2,..., f(t ) b n mod T a n for an unknown f(t ) n R[T ]. Snce the a s are dstnct, the polynomals T a 1,..., T a n are parwse relatvely prme n R[T ]. Therefore, by the Chnese remander theorem n R[T ], there s an f(t ) n R[T ] satsfyng all of the above congruences. It follows that f(a ) = b for all. We have no ntal control over deg f for the common soluton f. However, snce we can adjust f(t ) modulo (T a 1 ) (T a n ) wthout changng the congruence condtons, we can replace f(t ) wth ts remander under dvson by (T a 1 ) (T a n ), whch has degree n. Then deg f < n wth f(a ) = b for all. We have shown a desred f(t ) exsts. To see t s unque, suppose f 1 (T ) and f 2 (T ) both have degree less than n and satsfy f(t ) b 1 mod T a 1, f(t ) b 2 mod T a 2,..., f(t ) b n mod T a n. Then, by the unqueness n the Chnese remander theorem, we have f 1 (T ) f 2 (T ) mod (T a 1 ) (T a n ). Snce f 1 (T ) and f 2 (T ) have degree less than n, ths congruence modulo a polynomal of degree n mples f 1 (T ) = f 2 (T ) n R[T ].
THE CHINESE REMAINDER THEOREM 9 The fact that polynomal nterpolaton s dentcal to solvng a system of polynomal congruences (wth lnear modul) suggests that we should thnk about solvng a system of nteger congruences as arthmetc nterpolaton. There s nothng essental about R n Theorem 4.15 except that t s a feld. The Chnese remander theorem goes through for F [T ] wth F any feld, not just R, and Theorem 4.15 carres over to any feld: Theorem 4.16. Let F be any feld. For n dstnct numbers a 1, a 2,..., a n n F and any numbers b 1, b 2,..., b n n F, there s a unque polynomal f(t ) of degree < n n F [T ] such that f(a ) = b for all. The proof s dentcal to that of Theorem 4.15.