Mathematical Database NUMBER THEORY UNIT 2 CONGRUENCES 1. Basic Properties Recall that in Unit 0, we came across the problem of finding the odd one out among the following group of numbers: 13, 17, 25, 39, 45 We remarked that 39 is the odd one out, for it leaves a remainder of 3 when divided by 4, while the others leave a remainder of 1 when divided by 4. In view of this, integers can be classified into four types, according to whether they leave a remainder of 0, 1, 2 or 3 when divided by 4. Of course, there is no need to restrict ourselves to dividing by 4. The division algorithm (Lemma 2.2 in Unit 1) asserts that given any integers a, b with a ≠ 0 , there exist unique integers q, r, 0 ≤ r < | a | , such that b = aq + r . The number r is called the remainder when b is divided by a. It may take one of the values 0, 1, …, a − 1 . Hence we may classify the integers into a types according to their remainders upon division by a. This leads us to the following definition. Definition 1.1. Let m ≠ 0 be an integer. We say that x is congruent to y modulo m, denoted as x ≡ y (mod m), if m| x− y . Illustrations. 38 ≡ 74 (mod 4), 6≡ –1 (mod 7), 83 ≡ 123 (mod 10). Note that x ≡ y (mod m) means that x and y leave the same remainder when divided by m. As for divisibility, we have the following basic properties about congruences which are easy to verify. Page 1 of 11 Mathematical Database Theorem 1.1. Let a, b, c, d, m, n be integers, m ≠ 0 , a ≡ b (mod m), c ≡ d (mod m). Then (1) a ± c ≡ b ± d (mod m) (2) ac ≡ bd (mod m) (3) a n ≡ b n (mod m) (4) if n | a , n | b and (m, n) = 1, we have a b ≡ (mod m). n n Example 1.1. Find the remainder when (a) 82002 is divided by 7 (b) 32003 is divided by 26 (c) 197820 is divided by 125 Solution. (a) 82002 ≡ 12002 = 1 (mod 7). ∴ The remainder is 1. (b) 32003 = (33 )667 (32 ) = 27 66732 ≡ 166732 = 9 (mod 26) ∴ The remainder is 26. (c) 197820 ≡ ( −22) 20 = 48410 ≡ (−16)10 ≡ 2565 ≡ 65 = 2535 = 32(243) ≡ 32(−7) ≡ 26 (mod 125) ∴ The remainder is 26. Example 1.2. Show that a natural number N is divisible by 3 if and only if its sum of digits is divisible by 3. Solution. Write N = ak ak −1 a2 a1a0 in its decimal notation. Then N = ak × 10k + ak −1 ×10k −1 + ≡ ak × 1k + ak −1 × 1k −1 + = ak + ak −1 + + a2 × 102 + a1 × 10 + a0 × 1 + a2 × 12 + a1 × 1 + a0 × 1 + a2 + a1 + a0 (mod 3) Page 2 of 11 Mathematical Database Hence 3 | N if and only if 3 | sum of digits of N. Remark. Compare this proof with the one given in Unit 1. In this proof, we showed that N is congruent to its sum of digits modulo 3. Hence we can easily find the remainder of a number upon division by 3 by considering its sum of digits. Example 1.3. Show that the sequence 11, 111, 1111, … contains no perfect squares. Solution. For all integers n, n ≡ 0, 1, 2 or 3 (mod 4). If n ≡ 0 or 2 (mod 4), then n 2 ≡ 0 (mod 4). If n ≡ 1 or 3 (mod 4), then n 2 ≡ 1 (mod 4). Note that in the sequence 11, 111, 1111, …, all terms leave a remainder of 3 when divided by 4. Thus there is no perfect square in the sequence. Example 1.4. Find the largest even number which cannot be expressed as the sum of two odd composite numbers. Solution. Let n be an even number. If n ≡ 0 (mod 3), then we have n = 9 + (n − 9) . Since n − 9 is divisible by 3, it is an odd composite number whenever n > 12 . If n ≡ 1 (mod 3), then we have n = 25 + (n − 25) . Since n − 25 is divisible by 3, it is an odd composite number whenever n > 28 . If n ≡ 2 (mod 3), then we have n = 35 + (n − 35) . Since n − 35 is divisible by 3, it is an odd composite number whenever n > 38 . It follows that all even numbers greater than 38 can be expressed as the sum of two odd composite numbers. However, there is no way of writing 38 as the sum of two odd composite numbers (this can be seen by listing all odd composite numbers less than 38: 9, 15, 21, 25, 27, 35). Therefore, the answer is 38. Page 3 of 11 Mathematical Database 2. The Euler φ-function In Example 1.1, part (b), we found that our calculation is very much simplified by expressing the number as a power of 33 , because 33 ≡ 1 (mod 26). Therefore, in attempting to find the remainder when a certain power of a is divided by n, where a and n are given, we probably want to find an exponent k for which a k ≡ 1 (mod n). In the next section we will come across a theorem which enables us to find such an exponent efficiently. In order to understand the theorem, we first go over the Euler φ-function in this section. Definition 2.1. For positive integer n, we define φ (n) = number of positive integers not exceeding n that are relatively prime to n. Illustrations. φ (12) = 4 since 1, 5, 7, 11 are relatively prime to 12. φ (16) = 8 since 1, 3, 5, 7, 9, 11, 13, 15 are relatively prime to 16. The Euler φ-function turns out to be an important function in number theory on which many theorems are built. Before we proceed, let’s study some nice properties of the function which facilitate easy computation of φ (n) for a given n. Theorem 2.1. Let a, b be relatively prime natural numbers, p be a prime number and m be a positive integer. Then (a) φ (ab) = φ (a )φ (b) (b) φ ( p m ) = p m − p m −1 Illustrations. (a) φ (3) = 2 , φ (4) = 2 , φ (12) = 4 ; (b) φ (16) = φ (24 ) = 24 − 23 = 8 . Remark. Because of the property in (a), the function φ is said to be multiplicative. This is a very nice property because, if a function f : → is multiplicative, we need only know the value of f at prime powers. The other values can be computed via the prime factorization of a natural number. With the formula in (b), therefore, we can compute φ (n) easily for all n. Page 4 of 11 Mathematical Database Example 2.1. Find φ (360) . Solution. φ (360) = φ (23 × 32 × 5) = φ (23 ) × φ (32 ) × φ (5) = (23 − 2 2 )(32 − 31 )(51 − 50 ) = 96 . Example 2.2. Find all natural numbers n for which φ (n) is odd. Solution. Clearly, φ (1) = 1 is odd. Now suppose n > 1 . Let n = p1 1 p2 2 e e e pk k , where pi is prime and ei is a positive integer for i = 1, 2, …, k. Then φ (n) = ∏ ( pi e − pi e −1 ) . k i i i =1 e −1 For φ (n) to be odd, pi i − pi i e e −1 and pi i e −1 is odd for all i. If pi is odd, then pi i − pi i e e is even since both pi i are odd. So pi must be even, i.e. n = 2e for some e > 0 . Consequently, φ (n) = 2e − 2e −1 . This cannot be odd unless e = 1 , i.e. n = 2 . Indeed, we check that φ (2) = 1 is odd. Consequently, we see that φ (n) is odd only if n = 1 or 2. 3. Euler’s and Fermat’s Theorems With the concept of the Euler φ-function in mind, we can now go into Euler’s Theorem, which helps us find an exponent k for which a k ≡ 1 (mod n) given integers a and n under certain conditions. Theorem 3.1. (Euler’s Theorem) Let a and n be relatively prime natural numbers. Then aφ ( n ) ≡ 1 (mod n). Page 5 of 11 Mathematical Database Illustration. (3, 100) = 1, φ (100) = φ (22 )φ (52 ) = (22 − 21 )(52 − 51 ) = 40 . Thus 340 ≡ 1 (mod 100). Remark. Given natural numbers a and n, we say that b is an inverse of a modulo n if ab ≡ 1 (mod n). For example, 7 is an inverse of 4 (mod 9) since 4 × 7 ≡ 1 (mod 9). Inverses are useful in simplifying computations and solving congruence equations such as 4 x ≡ 3 (mod 7), but in general finding an inverse is not easy. Nevertheless, Euler’s Theorem tells us that when (a, n) = 1, aφ ( n )−1 is an inverse of a (mod n). Example 3.1. Find the last two digits of 17 2002 . Solution. As we have seen, φ (100) = 40 . Since (17, 100) = 1, Euler’s theorem asserts that 17 40 ≡ 1 (mod 100). ∴ 17 2002 ≡ (17 40 ) 17 2 ≡ 150 ⋅ 289 ≡ 89 (mod 100). 50 Hence the last two digits are 89. When p is prime, then φ ( p) = p − 1 . As a particular case of the Euler’s theorem, we have Theorem 3.2. (Fermat Little Theorem) Let p be a prime and (a, p) = 1. Then a p −1 ≡ 1 (mod p). Illustration. 2003 is prime. (1234, 2003) = 1. Thus 12342002 ≡ 1 (mod 2003). Example 3.2. Let p be a prime number, p ≡ 3 (mod 4) and p | a 2 + b 2 for some integers a and b. Prove that p | a and p | b . Solution. Suppose p /| a . Then we must have p /| b as well. Consequently, we have ( p, a) = ( p, b) = 1 and so Fermat Little Theorem applies. Page 6 of 11 Mathematical Database Since b 2 ≡ −a 2 (mod p), by Fermat Little Theorem, we have, on one hand, (a p −2 b ) ≡ ( a p − 2 ) ( −a 2 ) ≡ − ( a p −1 ) ≡ −12 = −1 (mod p), 2 2 2 so that (a p −2 b) p −1 2 = ( a p − 2b ) p −1 2 ≡ (−1) p −1 2 ≡ −1 (mod p), where we made use of the fact that p ≡ 3 (mod 4) which implies p −1 is odd. 2 On the other hand, a p − 2b is also relatively prime to p, so Fermat Little Theorem asserts that (a p −2 b) p −1 ≡ 1 (mod p). Since p ≠ 2 , this is a contradiction. So we must have p | a and hence p | b . 4. The Chinese Remainder Theorem To motivate our discussion, let’s consider the following example: A positive integer n leaves a remainder of 3 when divided by 5 and a remainder of 4 when divided by 7. What is the smallest possible value of n? Solving the question is not hard: we first note that the unit digit of n must be 3 or 8, and so n is among 3, 8, 13, 18, 23, 28, … We then find the smallest one among these integers which leaves a remainder of 4 upon division by 7. It is easy to see that the smallest n is 18. Note that the conditions imposed on n can be rephrased into t e system of congruences: n ≡ 3 (mod 5) n ≡ 4 (mod 7) and we have shown that the smallest positive n satisfying the system is 18. If we repeat the above process, it is not hard to see that n = 53, 88, 123, 158, … all satisfy the system and they occur at intervals of 35. Indeed, any integer n with n ≡ 18 (mod 35) satisfies the system. Page 7 of 11 Mathematical Database A natural question to ask is whether all such systems are solvable. A little thought would tell us that the answer is negative, for the system n ≡ 1 (mod 2) n ≡ 2 (mod 4) is clearly not solvable (as the first constraint requires n to be odd and the second constraint requires n to be even). Despite this negative result, an extra constraint would give us something encouraging, as given in the next theorem. Theorem 4.1. (Chinese remainder theorem) If b1 , b2 , …, bk are integers and m1 , m2 , …, mk are pairwise relatively prime integers, then the system x ≡ b1 (mod m1 ) x ≡ b (mod m ) 2 2 x ≡ bk (mod mk ) is solvable and the solution is unique modulo m1m2 mk . Proof. We first prove the uniqueness, and then prove the existence. (Uniqueness) Suppose x and x' both satisfy the system. Then x ≡ x ' (mod mi ) for i = 1, 2, …, k, i.e. mi | x − x ' for i = 1, 2, …, k. Since m1 , m2 , …, mk are pairwisely relatively prime, we have m1m2 x ≡ x ' (mod m1m2 mk | x − x ' , i.e. mk ). (Existence) Define M j = m1m2 mk for j = 1, 2, …, k. Set mj φ ( m1 ) x = M1 Then for j = 1, 2, …, k, x ≡ M j φ (m j ) φ ( m2 ) b1 + M 2 b2 + + Mk φ ( mk ) bk . b j ≡ (1)b j = b j (mod m j ) where we made use of the fact that m j | M r for r ≠ j and the Euler’s theorem (noting that m j is relatively prime to M j for all j). Page 8 of 11 Mathematical Database Q.E.D. In the above proof we gave an explicit formula to find x, but in practice this is rarely used as the number gets too large when we take powers. There is another formula which overcomes this difficulty but which is not as simple as the preceding one. Recall that b is said to be an inverse of a modulo n if ab ≡ 1 (mod n). It can be shown that such b exists if and only if (a, n) = 1 (see exercise 8). Now, (m j , M j ) = 1 for all j, where M j is defined as above, since the mi ’s are pairwise relatively prime. Hence M j has an inverse modulo m j , which we denote by M j . Then a solution for the system in Theorem 4.1 can be written as x = b1M 1 M 1 + b2 M 2 M 2 + + bk M k M k . We leave it to the reader to verify that such x indeed satisfies the system. Example 4.1. Find all integers x for which x ≡ 2 (mod 3), x ≡ 3 (mod 5) and x ≡ 4 (mod 7). Solution. Since 3, 5, 7 are pairwise relatively prime, the Chinese remainder theorem asserts that there is a unique solution modulo 3 × 5 × 7 = 105 . Now m1 = 3 , m2 = 5 , m3 = 7 , M 1 = 35 , M 2 = 21 , M 3 = 15 , M 1 = 2 , M 2 = 1 , M 3 = 1 , so one solution for x is given by x = 2 × 35 × 2 + 3 × 21× 1 + 4 × 15 × 1 = 263 . Note that 263 ≡ 53 (mod 105), so the general solution is x = 53 + 105t for any integer t. 5. Exercises 1. Prove or disprove each of the following statements. All variables denote natural numbers. (a) If a ≡ b (mod m), then a 2 ≡ b 2 (mod m). (b) If a ≡ b (mod m), then a 2 ≡ b 2 (mod m 2 ). (c) If a 2 ≡ b 2 (mod m 2 ), then a ≡ b (mod m). Page 9 of 11 Mathematical Database (d) If ax ≡ bx (mod mx), then a ≡ b (mod m). (e) If m > n , then φ (m) > φ (n) . (f) If p > q and m > 1, then φ (m p ) > φ (m q ) . 2. Find the remainder when 12345678 is divided by 13. 3. Show that a natural number N is divisible by 9 if and only if its sum of digits is divisible by 9. 4. In Unit 1 and its exercises, we came across various divisibility tests and proved their validity using divisibility arguments. Try to rephrase the proofs in the language of congruences that we have been using throughout this unit. 5. Find all prime numbers p for which 2 p + p 2 is prime. 6. Prove that there are infinitely many prime numbers p satisfying p ≡ 3 (mod 4). 7. Suppose n has k distinct prime factors p1 , p2 , …, pk . Show that 1 1 φ ( n) = n 1 − 1 − p1 p2 8. 1 1 − . pk (a) Let a, n be integers, n ≠ 0 . Show that a has an inverse modulo n if and only if a and n are relatively prime. (Hint: Recall that there exist integers u, v such that cu + dv = gcd(c, d ) .) (b) In the condition of (a), show that the inverse is unique modulo n. 9. Show that x = b1M 1 M 1 + b2 M 2 M 2 + + bk M k M k satisfies the system of congruences in the statement of Theorem 4.1. Page 10 of 11 Mathematical Database 9. (a) Let p1 , p2 , …, p2n be distinct prime numbers. Show that there is an integer x such that p2i −1 p2i divides x + i for i = 1, 2, …, n. (b) We say that a positive integer k is ‘good’ if it is not the power of a prime number. Using (a), show that for every natural number n we can find n consecutive ‘good’ integers. (Remark: Part (b) is essentially the same as a problem in IMO 1989.) 10. (a) Wilson’s Theorem asserts that ( p − 1)! ≡ −1 (mod p) for all prime numbers p. Give a proof of this fact. (Hint: Group the terms of ( p − 1)! into pairs.) (b) Show that the converse of Wilson’s Theorem is also true. (c) In view of (a) and (b), we see that (n − 1)! ≡ −1 (mod n) if and only if n is prime. This gives a test of whether a given natural number n is prime. But in practice such a test is rarely used. Suggest a reason for this. 11. (IMO 2002 Hong Kong Team Selection Test 1) Considering (mod 4) or otherwise, prove that if a, b, c, d are integers satisfying (3a + 5b)(7b + 11c)(13c + 17 d )(19d + 23a ) = 20012001 then a must be even. 12. (IMO 2001) Let n be an odd integer greater than 1, and let k1 , k2 , …, kn be given integers. For each of the n! permutations a = (a1 , a2 , … , an ) of 1, 2, …, n, let n S (a ) = ∑ ki ai . i =1 Prove that there are two permutations b and c, b ≠ c , such that n! is a divisor of S (b) − S (c). Page 11 of 11