Congruence

Contents

This note continues the Divisibility note. As before, all variables are integers unless otherwise specified, and the modulus mm is always a positive integer.

Definitions and Basic Properties

Definition 1 (Congruence).

Let a,b∈Za, b \in \bbZ and m∈Nm \in \bbN. We say aa is congruent to bb modulo mm and write a≡b(modm)a \equiv b \pmod{m} if m∣(b−a)m \divides (b - a), in other words, b−a=mkb - a = mk for some k∈Zk \in \bbZ. The integer mm is called the modulus. If m∤(b−a)m \nmid (b - a), we write a≢b(modm)a \not\equiv b \pmod{m}.

Symbolically,

a≡b(modm)  ⇔  (∃k∈Z)(b−a=mk).a \equiv b \pmod{m} \;\Leftrightarrow\; (\exists k \in \bbZ)(b - a = mk).

For example, 17≡2(mod5)17 \equiv 2 \pmod{5} because 2−17=−15=5×(−3)2 - 17 = -15 = 5 \times (-3), and −1≡9(mod10)-1 \equiv 9 \pmod{10} because 9−(−1)=109 - (-1) = 10.

Recall the division algorithm: for every n∈Zn \in \bbZ there are unique integers qq and rr such that n=qm+rn = qm + r and 0≤r<m0 \leq r < m. We call rr the remainder of nn modulo mm and write r=n mod mr = n \bmod m. Since r−n=−qmr - n = -qm, we have n≡r(modm)n \equiv r \pmod{m}; that is, every integer is congruent to exactly one of 0,1,…,m−10, 1, \ldots, m - 1. Moreover,

a≡b(modm)  ⇔  a mod m=b mod m,a \equiv b \pmod{m} \;\Leftrightarrow\; a \bmod m = b \bmod m,

so two integers are congruent modulo mm precisely when they leave the same remainder upon division by mm.

Basic Properties.

  1. (Reflexivity) a≡a(modm)a \equiv a \pmod{m}.
    (Proof: a−a=0=m×0a - a = 0 = m \times 0.)
  2. (Symmetry) If a≡b(modm)a \equiv b \pmod{m}, then b≡a(modm)b \equiv a \pmod{m}.
    (Proof: If b−a=mkb - a = mk, then a−b=m(−k)a - b = m(-k).)
  3. (Transitivity) If a≡b(modm)a \equiv b \pmod{m} and b≡c(modm)b \equiv c \pmod{m}, then a≡c(modm)a \equiv c \pmod{m}.
    (Proof: Write b−a=mk1b - a = mk_1 and c−b=mk2c - b = mk_2. Then c−a=(c−b)+(b−a)=m(k1+k2)c - a = (c - b) + (b - a) = m(k_1 + k_2).)
  4. (Addition and Subtraction) If a1≡a2(modm)a_1 \equiv a_2 \pmod{m} and b1≡b2(modm)b_1 \equiv b_2 \pmod{m}, then a1±b1≡a2±b2(modm)a_1 \pm b_1 \equiv a_2 \pm b_2 \pmod{m}.
    (Proof: (a2±b2)−(a1±b1)=(a2−a1)±(b2−b1)(a_2 \pm b_2) - (a_1 \pm b_1) = (a_2 - a_1) \pm (b_2 - b_1), and mm divides both terms.)
  5. (Multiplication) If a1≡a2(modm)a_1 \equiv a_2 \pmod{m} and b1≡b2(modm)b_1 \equiv b_2 \pmod{m}, then a1b1≡a2b2(modm)a_1 b_1 \equiv a_2 b_2 \pmod{m}.
    (Proof: a2b2−a1b1=a2(b2−b1)+b1(a2−a1)a_2 b_2 - a_1 b_1 = a_2 (b_2 - b_1) + b_1 (a_2 - a_1), and mm divides both terms.)
  6. (Powers) If a≡b(modm)a \equiv b \pmod{m}, then ak≡bk(modm)a^k \equiv b^k \pmod{m} for every non-negative integer kk.
    (Proof: Apply (e) repeatedly, i.e., by induction on kk.)

In other words, one can add, subtract, or multiply two congruences with the same modulus, exactly as with ordinary equations. When computing modulo mm, we may therefore replace any number by anything congruent to it, typically its remainder, at any stage of a calculation.

Remark. Division is not allowed in general. For instance, 2×3≡2×8(mod10)2 \times 3 \equiv 2 \times 8 \pmod{10}, but 3≢8(mod10)3 \not\equiv 8 \pmod{10}. One cannot cancel the factor 22 because gcd⁡(2,10)≠1\gcd(2, 10) \neq 1.

Example 2.

Find the remainder when 21002^{100} is divided by 77.

Solution

Since 23=8≡1(mod7)2^3 = 8 \equiv 1 \pmod{7}, property (f) gives 299=(23)33≡133=1(mod7)2^{99} = \left(2^3\right)^{33} \equiv 1^{33} = 1 \pmod{7}. By property (e), 2100=2×299≡2×1=2(mod7)2^{100} = 2 \times 2^{99} \equiv 2 \times 1 = 2 \pmod{7}. The remainder is 22.

Divisibility Criteria

In this section, we use the basic properties of congruence to explain the divisibility criteria for 22, 33, 44, 55, 99, and 1111. Throughout, a positive integer nn is written in terms of its decimal digits a0,a1,…,ak∈{0,1,…,9}a_0, a_1, \ldots, a_k \in \{0, 1, \ldots, 9\} as

n=∑i=0kai×10i=ak×10k+⋯+a1×10+a0.n = \sum_{i=0}^{k} a_i \times 10^i = a_k \times 10^k + \cdots + a_1 \times 10 + a_0.

Divisibility by 2. Write n=10a+bn = 10a + b, where b=a0b = a_0 is the units digit. Since 10≡0(mod2)10 \equiv 0 \pmod{2}, we have 10a+b≡b(mod2)10a + b \equiv b \pmod{2}. Hence the divisibility of nn by 22 depends only on the units digit.

Divisibility by 3. Since 10≡1(mod3)10 \equiv 1 \pmod{3}, we have 10i≡1(mod3)10^i \equiv 1 \pmod{3} for every non-negative integer ii. It follows that

∑i=0kai×10i≡∑i=0kai(mod3).\sum_{i=0}^{k} a_i \times 10^i \equiv \sum_{i=0}^{k} a_i \pmod{3}.

That is, nn is congruent to its digit sum modulo 33.

Divisibility by 4. Write n=100a+bn = 100a + b, where b=10a1+a0b = 10a_1 + a_0 is the number formed by the last two digits. Since 100=4×25≡0(mod4)100 = 4 \times 25 \equiv 0 \pmod{4}, we have 100a+b≡b(mod4)100a + b \equiv b \pmod{4}. Hence the divisibility of nn by 44 depends only on the last two digits.

Divisibility by 5. Write n=10a+bn = 10a + b, where b=a0b = a_0 is the units digit. Since 10≡0(mod5)10 \equiv 0 \pmod{5}, we have 10a+b≡b(mod5)10a + b \equiv b \pmod{5}. Hence the divisibility of nn by 55 depends only on the units digit.

Divisibility by 9. Since 10≡1(mod9)10 \equiv 1 \pmod{9}, we have 10i≡1(mod9)10^i \equiv 1 \pmod{9} for every non-negative integer ii. It follows that

∑i=0kai×10i≡∑i=0kai(mod9).\sum_{i=0}^{k} a_i \times 10^i \equiv \sum_{i=0}^{k} a_i \pmod{9}.

That is, nn is congruent to its digit sum modulo 99.

Divisibility by 11. Since 10≡−1(mod11)10 \equiv -1 \pmod{11}, we have 10i≡(−1)i(mod11)10^i \equiv (-1)^i \pmod{11} for every non-negative integer ii. It follows that

∑i=0kai×10i≡∑i=0k(−1)iai=a0−a1+a2−⋯(mod11).\sum_{i=0}^{k} a_i \times 10^i \equiv \sum_{i=0}^{k} (-1)^i a_i = a_0 - a_1 + a_2 - \cdots \pmod{11}.

That is, nn is congruent modulo 1111 to its alternating digit sum, starting with a plus sign at the units digit.

The congruences above not only give us a way to determine whether a positive integer nn is divisible by m=2m = 2, 33, 44, 55, 99, or 1111; they also tell us how to find the remainder n mod mn \bmod m efficiently.

Example 3.

Let n=8,675,309n = 8{,}675{,}309. Its digit sum is 8+6+7+5+3+0+9=388 + 6 + 7 + 5 + 3 + 0 + 9 = 38, so n≡38≡2(mod9)n \equiv 38 \equiv 2 \pmod{9} and n≡38≡2(mod3)n \equiv 38 \equiv 2 \pmod{3}. Its alternating digit sum, starting from the units digit, is 9−0+3−5+7−6+8=169 - 0 + 3 - 5 + 7 - 6 + 8 = 16, so n≡16≡5(mod11)n \equiv 16 \equiv 5 \pmod{11}. Its last two digits form 09≡1(mod4)09 \equiv 1 \pmod{4}, so n≡1(mod4)n \equiv 1 \pmod{4}.

Exercise 4.

Without performing long division, find the remainder when

  1. 1,234,5671{,}234{,}567 is divided by 99;
  2. 918,082918{,}082 is divided by 1111;
  3. 250×1050+72^{50} \times 10^{50} + 7 is divided by 44.

Hint: For (c), first find the last two digits of the number.

Exercise 5.

Find the digit dd such that the four-digit number 3d48‾\overline{3d48} is divisible by 3636.

Hint: Since 36=4×936 = 4 \times 9 and gcd⁡(4,9)=1\gcd(4, 9) = 1, a number is divisible by 3636 if and only if it is divisible by both 44 and 99 (see Proposition 23 of the Divisibility note).

Exercise 6.

Let N=abc‾N = \overline{abc} be a three-digit number and let N′=cba‾N' = \overline{cba} be the number obtained by reversing its digits. Prove that 99∣(N−N′)99 \divides (N - N').

Hint: Show that N≡N′(mod9)N \equiv N' \pmod{9} and N≡N′(mod11)N \equiv N' \pmod{11}, then use gcd⁡(9,11)=1\gcd(9, 11) = 1.

Answers

4. (a) The digit sum is 28≡1(mod9)28 \equiv 1 \pmod{9}, so the remainder is 11. (b) The alternating digit sum is 2−8+0−8+1−9=−22≡0(mod11)2 - 8 + 0 - 8 + 1 - 9 = -22 \equiv 0 \pmod{11}, so the remainder is 00. (c) 250×10502^{50} \times 10^{50} is a multiple of 100100, so the number ends in 0707; since 7≡3(mod4)7 \equiv 3 \pmod{4}, the remainder is 33.

5. The last two digits 48=4×1248 = 4 \times 12, so the number is always divisible by 44. For divisibility by 99, we need 3+d+4+8=15+d≡0(mod9)3 + d + 4 + 8 = 15 + d \equiv 0 \pmod{9}, so d=3d = 3. Indeed, 3348=36×933348 = 36 \times 93.

6. Both NN and N′N' have digit sum a+b+ca + b + c, so N≡N′(mod9)N \equiv N' \pmod{9}. The alternating digit sums are c−b+ac - b + a and a−b+ca - b + c, which are equal, so N≡N′(mod11)N \equiv N' \pmod{11}. Since 9∣(N−N′)9 \divides (N - N'), 11∣(N−N′)11 \divides (N - N'), and gcd⁡(9,11)=1\gcd(9, 11) = 1, we conclude 99∣(N−N′)99 \divides (N - N'). (Directly: N−N′=99(a−c)N - N' = 99(a - c).)

Conversion from Decimal to Binary Representation

Every non-negative integer nn has a unique binary (base 22) representation of the form

n=ak×2k+ak−1×2k−1+⋯+a1×2+a0,n = a_k \times 2^k + a_{k-1} \times 2^{k-1} + \cdots + a_1 \times 2 + a_0,

where ai∈{0,1}a_i \in \{0, 1\} for each i=0,1,…,ki = 0, 1, \ldots, k. We write n=(akak−1⋯a1a0)2n = (a_k a_{k-1} \cdots a_1 a_0)_2.

Every term except a0a_0 is a multiple of 22, so from the basic properties of congruence, n≡a0(mod2)n \equiv a_0 \pmod{2}. Since a0∈{0,1}a_0 \in \{0, 1\}, this means a0=n mod 2a_0 = n \bmod 2. Moreover,

n1:=n−a02n_1 := \frac{n - a_0}{2}

is an integer, and its binary representation is

n1=ak×2k−1+ak−1×2k−2+⋯+a2×2+a1.n_1 = a_k \times 2^{k-1} + a_{k-1} \times 2^{k-2} + \cdots + a_2 \times 2 + a_1.

So one can find the next binary digit a1=n1 mod 2a_1 = n_1 \bmod 2. Repeating this process gives us the values of a0,a1,…,aka_0, a_1, \ldots, a_k.

Algorithm 7 (Decimal to Binary).

Given a non-negative integer nn, set n0=nn_0 = n. For i=0,1,2,…i = 0, 1, 2, \ldots, define

ai=ni mod 2,ni+1=ni−ai2.a_i = n_i \bmod 2, \qquad n_{i+1} = \frac{n_i - a_i}{2}.

Stop when ni+1=0n_{i+1} = 0. Then n=(akak−1⋯a1a0)2n = (a_k a_{k-1} \cdots a_1 a_0)_2, where kk is the last index computed.

Example 8.

We convert 3737 to binary.

iinin_iai=ni mod 2a_i = n_i \bmod 2
0371
1180
291
340
420
511
60

Reading the digits from bottom to top, 37=(100101)237 = (100101)_2. Check: 25+22+20=32+4+1=372^5 + 2^2 + 2^0 = 32 + 4 + 1 = 37.

Exercise 9.

Convert 100100 and 255255 to binary.

Answer

100=(1100100)2100 = (1100100)_2 and 255=(11111111)2255 = (11111111)_2.

Cancellation Law and Multiplicative Inverse

We remarked earlier that division is not allowed in general. The following proposition says exactly when a common factor may be cancelled.

Proposition 10 (Cancellation Law).

If ka≡kb(modm)ka \equiv kb \pmod{m} and gcd⁡(k,m)=1\gcd(k, m) = 1, then a≡b(modm)a \equiv b \pmod{m}.

Proof.

By assumption, m∣(kb−ka)=k(b−a)m \divides (kb - ka) = k(b - a). Since gcd⁡(m,k)=1\gcd(m, k) = 1, Euclid’s Lemma (Proposition 17 of the Divisibility note) gives m∣(b−a)m \divides (b - a), i.e., a≡b(modm)a \equiv b \pmod{m}.

For example, 3×7≡3×2(mod5)3 \times 7 \equiv 3 \times 2 \pmod{5} since 21−6=1521 - 6 = 15, and as gcd⁡(3,5)=1\gcd(3, 5) = 1 we may cancel the 33 to get 7≡2(mod5)7 \equiv 2 \pmod{5}. In the earlier remark, 2×3≡2×8(mod10)2 \times 3 \equiv 2 \times 8 \pmod{10}, the factor 22 cannot be cancelled because gcd⁡(2,10)=2≠1\gcd(2, 10) = 2 \neq 1.

Definition 11 (Multiplicative Inverse).

Let a∈Za \in \bbZ and m∈Nm \in \bbN. A multiplicative inverse of aa modulo mm is an integer xx such that ax≡1(modm)ax \equiv 1 \pmod{m}. When it exists, it is unique modulo mm (see Proposition 12), and we denote it by a−1a^{-1}.

For example, 3−1≡2(mod5)3^{-1} \equiv 2 \pmod{5} since 3×2=6≡1(mod5)3 \times 2 = 6 \equiv 1 \pmod{5}.

Remark. Do not confuse this with the reciprocal a−1=1aa^{-1} = \frac{1}{a}. The notations are the same, but in the context of congruence, a−1a^{-1} denotes an integer, determined modulo mm.

Proposition 12 (Existence of Multiplicative Inverse).

The multiplicative inverse of aa modulo mm exists if and only if gcd⁡(a,m)=1\gcd(a, m) = 1. In that case, it is unique modulo mm.

Proof.

Suppose gcd⁡(a,m)=1\gcd(a, m) = 1. Then there exist integers xx and yy such that ax+my=1ax + my = 1 (see Proposition 4 of the Divisibility note). Reducing modulo mm gives ax≡1(modm)ax \equiv 1 \pmod{m}; in other words, xx is a multiplicative inverse of aa modulo mm.

Conversely, suppose ax≡1(modm)ax \equiv 1 \pmod{m}, say 1−ax=my1 - ax = my. Then ax+my=1ax + my = 1, so every common divisor of aa and mm divides 11, hence gcd⁡(a,m)=1\gcd(a, m) = 1.

For uniqueness, if ax≡1≡ax′(modm)ax \equiv 1 \equiv ax' \pmod{m}, then the Cancellation Law (Proposition 10, with k=ak = a) gives x≡x′(modm)x \equiv x' \pmod{m}.

In practice, a−1a^{-1} is found either by trial for small mm (try x=1,2,…,m−1x = 1, 2, \ldots, m - 1) or by the Extended Euclidean Algorithm from the Divisibility note, which produces xx and yy with ax+my=1ax + my = 1 directly.

Exercise 13.

For each of the following, determine whether the multiplicative inverse exists. If it does, find it.

  1. 4−1(mod9)4^{-1} \pmod{9};
  2. 6−1(mod15)6^{-1} \pmod{15};
  3. 7−1(mod26)7^{-1} \pmod{26};
  4. 10−1(mod35)10^{-1} \pmod{35};
  5. 11−1(mod30)11^{-1} \pmod{30};
  6. 17−1(mod60)17^{-1} \pmod{60}.

Hint: First compute the gcd. For (f), use the Extended Euclidean Algorithm.

Answers
  1. gcd⁡(4,9)=1\gcd(4, 9) = 1, and 4×7=28≡1(mod9)4 \times 7 = 28 \equiv 1 \pmod{9}, so 4−1≡7(mod9)4^{-1} \equiv 7 \pmod{9}.

  2. gcd⁡(6,15)=3≠1\gcd(6, 15) = 3 \neq 1, so no inverse exists.

  3. gcd⁡(7,26)=1\gcd(7, 26) = 1, and 7×15=105≡1(mod26)7 \times 15 = 105 \equiv 1 \pmod{26}, so 7−1≡15(mod26)7^{-1} \equiv 15 \pmod{26}.

  4. gcd⁡(10,35)=5≠1\gcd(10, 35) = 5 \neq 1, so no inverse exists.

  5. gcd⁡(11,30)=1\gcd(11, 30) = 1, and 11×11=121≡1(mod30)11 \times 11 = 121 \equiv 1 \pmod{30}, so 11−1≡11(mod30)11^{-1} \equiv 11 \pmod{30}.

  6. The Euclidean Algorithm gives 60=3×17+960 = 3 \times 17 + 9, 17=1×9+817 = 1 \times 9 + 8, 9=1×8+19 = 1 \times 8 + 1. Working backwards,

    1=9−8=9−(17−9)=2×9−17=2×(60−3×17)−17=2×60−7×17,1 = 9 - 8 = 9 - (17 - 9) = 2 \times 9 - 17 = 2 \times (60 - 3 \times 17) - 17 = 2 \times 60 - 7 \times 17,

    so 17−1≡−7≡53(mod60)17^{-1} \equiv -7 \equiv 53 \pmod{60}. Check: 17×53=901=15×60+117 \times 53 = 901 = 15 \times 60 + 1.

With multiplicative inverses, we can now solve linear congruences by “dividing” by aa.

Proposition 14.

Let a,b∈Za, b \in \bbZ and m∈Nm \in \bbN with gcd⁡(a,m)=1\gcd(a, m) = 1. Then the congruence

ax≡b(modm)ax \equiv b \pmod{m}

has a solution in xx, and the solution is unique modulo mm; namely, x≡a−1b(modm)x \equiv a^{-1} b \pmod{m}.

Proof.

By Proposition 12, a−1a^{-1} exists. If x≡a−1b(modm)x \equiv a^{-1} b \pmod{m}, then ax≡aa−1b≡b(modm)ax \equiv a a^{-1} b \equiv b \pmod{m}, so xx is a solution. Conversely, if ax≡b(modm)ax \equiv b \pmod{m}, multiplying both sides by a−1a^{-1} gives x≡a−1ax≡a−1b(modm)x \equiv a^{-1} a x \equiv a^{-1} b \pmod{m}.

Remark. If g=gcd⁡(a,m)>1g = \gcd(a, m) > 1, the congruence ax≡b(modm)ax \equiv b \pmod{m} is equivalent to the equation ax+my=bax + my = b, which has integer solutions if and only if g∣bg \divides b (see Proposition 4 of the Divisibility note). For instance, 2x≡3(mod6)2x \equiv 3 \pmod{6} has no solution, while 2x≡4(mod6)2x \equiv 4 \pmod{6} has the two solutions x≡2x \equiv 2 and x≡5(mod6)x \equiv 5 \pmod{6}, so the solution is no longer unique modulo mm.

Example 15.

Solve 15x≡23(mod17)15x \equiv 23 \pmod{17}.

Solution

Since 1717 is prime and 17∤1517 \nmid 15, we have gcd⁡(15,17)=1\gcd(15, 17) = 1, so 15−115^{-1} exists. We find it using the Extended Euclidean Algorithm:

17=1×15+2,15=7×2+1.\begin{aligned} 17 &= 1 \times 15 + 2, \\ 15 &= 7 \times 2 + 1. \end{aligned}

Working backwards,

1=15−7×2=15−7×(17−15)=8×15−7×17,1 = 15 - 7 \times 2 = 15 - 7 \times (17 - 15) = 8 \times 15 - 7 \times 17,

so 15×8≡1(mod17)15 \times 8 \equiv 1 \pmod{17}, i.e., 15−1≡8(mod17)15^{-1} \equiv 8 \pmod{17}. Multiplying both sides of the congruence by 88,

x≡8×23=184=10×17+14≡14(mod17).x \equiv 8 \times 23 = 184 = 10 \times 17 + 14 \equiv 14 \pmod{17}.

Check: 15×14=210=23+187=23+11×1715 \times 14 = 210 = 23 + 187 = 23 + 11 \times 17. Therefore the solutions are exactly the integers x≡14(mod17)x \equiv 14 \pmod{17}.

Chinese Remainder Theorem

Let us begin with a simple observation. Any integer nn modulo m=10m = 10 has 1010 possible remainders 0,1,…,90, 1, \ldots, 9. For each of these values, let us compute n mod 2n \bmod 2 and n mod 5n \bmod 5.

n mod 10n \bmod 100123456789
n mod 2n \bmod 20101010101
n mod 5n \bmod 50123401234

From the table, we see that each of the 2×5=102 \times 5 = 10 possible pairs (n mod 2, n mod 5)(n \bmod 2,\, n \bmod 5) appears exactly once. Hence the values of n mod 2n \bmod 2 and n mod 5n \bmod 5 uniquely determine the value of n mod 10n \bmod 10. In other words, if you know the remainder of nn modulo 22 and the remainder of nn modulo 55, then you also know the remainder of nn modulo 1010.

Now, let us consider a similar table below.

n mod 12n \bmod 1201234567891011
n mod 2n \bmod 2010101010101
n mod 6n \bmod 6012345012345

This time, n mod 2n \bmod 2 and n mod 6n \bmod 6 do not determine the value of n mod 12n \bmod 12. For example, n=1n = 1 and n=7n = 7 give the same pair (1,1)(1, 1). Meanwhile, half of the 2×6=122 \times 6 = 12 possible pairs, such as (0,1)(0, 1), never appear at all: since 2∣62 \divides 6, the remainder modulo 66 already determines the remainder modulo 22. The difference between the two tables is that gcd⁡(2,5)=1\gcd(2, 5) = 1, while gcd⁡(2,6)=2≠1\gcd(2, 6) = 2 \neq 1.

Theorem 16 (Chinese Remainder Theorem).

Suppose m1,m2,…,mkm_1, m_2, \ldots, m_k are pairwise coprime, i.e., gcd⁡(mi,mj)=1\gcd(m_i, m_j) = 1 for i≠ji \neq j. Then for any integers a1,a2,…,aka_1, a_2, \ldots, a_k, the following system of congruences has a unique solution modulo m=m1m2⋯mkm = m_1 m_2 \cdots m_k.

x≡a1(modm1),x≡a2(modm2),    ⋮x≡ak(modmk).\begin{aligned} x &\equiv a_1 \pmod{m_1}, \\ x &\equiv a_2 \pmod{m_2}, \\ &\;\;\vdots \\ x &\equiv a_k \pmod{m_k}. \end{aligned}
Proof sketch.

Uniqueness. Suppose xx and yy are both solutions. Then x≡y(modmi)x \equiv y \pmod{m_i}, i.e., mi∣(x−y)m_i \divides (x - y), for every ii. Since the mim_i are pairwise coprime, repeated application of Proposition 23 of the Divisibility note (if a∣na \divides n, b∣nb \divides n, and gcd⁡(a,b)=1\gcd(a, b) = 1, then ab∣nab \divides n) gives m∣(x−y)m \divides (x - y), i.e., x≡y(modm)x \equiv y \pmod{m}.

Existence. Consider the mm remainders 0,1,…,m−10, 1, \ldots, m - 1, and send each one to its tuple of remainders (x mod m1,…,x mod mk)(x \bmod m_1, \ldots, x \bmod m_k), as in the first table above. By uniqueness, no two of them give the same tuple. But there are exactly m1m2⋯mk=mm_1 m_2 \cdots m_k = m possible tuples, so every tuple, in particular (a1 mod m1,…,ak mod mk)(a_1 \bmod m_1, \ldots, a_k \bmod m_k), appears exactly once.

Example 17 (Sunzi Suanjing).

Find all integers xx such that

x≡2(mod3),x≡3(mod5),x≡2(mod7).\begin{aligned} x &\equiv 2 \pmod{3}, \\ x &\equiv 3 \pmod{5}, \\ x &\equiv 2 \pmod{7}. \end{aligned}
Solution

The moduli 33, 55, 77 are pairwise coprime, so by the Chinese Remainder Theorem there is exactly one solution modulo 105105. The first and third congruences say 3∣(x−2)3 \divides (x - 2) and 7∣(x−2)7 \divides (x - 2), so 21∣(x−2)21 \divides (x - 2), i.e., x≡2(mod21)x \equiv 2 \pmod{21}. We list the candidates below 105105 and check them modulo 55:

xx223446586
x mod 5x \bmod 523401

Only x=23x = 23 works. Therefore the solutions are exactly the integers x≡23(mod105)x \equiv 23 \pmod{105}.

Remark. Listing candidates is usually the fastest method on the AMC. For larger moduli, the Extended Euclidean Algorithm from the Divisibility note gives a systematic method: for instance, to solve x≡a1(modm1)x \equiv a_1 \pmod{m_1} and x≡a2(modm2)x \equiv a_2 \pmod{m_2}, find u,vu, v with m1u+m2v=1m_1 u + m_2 v = 1; then x=a2m1u+a1m2vx = a_2 m_1 u + a_1 m_2 v is a solution.

Exercise 18.

Find the smallest positive integer nn that leaves a remainder of 11 when divided by 33, a remainder of 22 when divided by 44, and a remainder of 33 when divided by 55.

Hint: Notice that n+2n + 2 is divisible by 33, 44, and 55.

Exercise 19.

Show that the system

x≡1(mod4),x≡2(mod6)x \equiv 1 \pmod{4}, \qquad x \equiv 2 \pmod{6}

has no solution. Why does this not contradict the Chinese Remainder Theorem?

Hint: Consider x mod 2x \bmod 2.

Answers

18. Since n≡−2(mod3)n \equiv -2 \pmod{3}, n≡−2(mod4)n \equiv -2 \pmod{4}, and n≡−2(mod5)n \equiv -2 \pmod{5}, and 33, 44, 55 are pairwise coprime, we get n≡−2(mod60)n \equiv -2 \pmod{60}. The smallest positive such nn is 5858.

19. The first congruence forces xx to be odd, while the second forces xx to be even. There is no contradiction because gcd⁡(4,6)=2≠1\gcd(4, 6) = 2 \neq 1, so the theorem does not apply.

Practice Problems

  1. What is the remainder when 1!+2!+3!+⋯+100!1! + 2! + 3! + \cdots + 100! is divided by 1212?

    (A) 0(B) 3(C) 6(D) 9(E) 11\textup{(A)}\ 0 \qquad \textup{(B)}\ 3 \qquad \textup{(C)}\ 6 \qquad \textup{(D)}\ 9 \qquad \textup{(E)}\ 11
  2. What is the units digit of 720267^{2026}?

    (A) 1(B) 3(C) 5(D) 7(E) 9\textup{(A)}\ 1 \qquad \textup{(B)}\ 3 \qquad \textup{(C)}\ 5 \qquad \textup{(D)}\ 7 \qquad \textup{(E)}\ 9
  3. What are the last two digits of 31003^{100}?

    (A) 01(B) 21(C) 43(D) 49(E) 81\textup{(A)}\ 01 \qquad \textup{(B)}\ 21 \qquad \textup{(C)}\ 43 \qquad \textup{(D)}\ 49 \qquad \textup{(E)}\ 81
  4. 2017 AMC 10B, Problem 23
  5. A school has between 100100 and 200200 students. When they line up in rows of 44, one student is left over; in rows of 55, two are left over; and in rows of 77, three are left over. How many students are there?

    (A) 117(B) 137(C) 157(D) 177(E) 197\textup{(A)}\ 117 \qquad \textup{(B)}\ 137 \qquad \textup{(C)}\ 157 \qquad \textup{(D)}\ 177 \qquad \textup{(E)}\ 197

Solutions

Problem 1

(D) 9. For k≥4k \geq 4, k!k! contains the factors 33 and 44, so k!≡0(mod12)k! \equiv 0 \pmod{12}. Hence the sum is congruent to 1!+2!+3!=9(mod12)1! + 2! + 3! = 9 \pmod{12}.

Problem 2

(E) 9. We work modulo 1010. Since 72=49≡−1(mod10)7^2 = 49 \equiv -1 \pmod{10}, we get 72026=(72)1013≡(−1)1013=−1≡9(mod10)7^{2026} = \left(7^2\right)^{1013} \equiv (-1)^{1013} = -1 \equiv 9 \pmod{10}.

Problem 3

(A) 01. We work modulo 100100. Since 35=243≡43(mod100)3^5 = 243 \equiv 43 \pmod{100}, we get 310≡432=1849≡49(mod100)3^{10} \equiv 43^2 = 1849 \equiv 49 \pmod{100} and 320≡492=2401≡1(mod100)3^{20} \equiv 49^2 = 2401 \equiv 1 \pmod{100}. Therefore 3100=(320)5≡1(mod100)3^{100} = \left(3^{20}\right)^5 \equiv 1 \pmod{100}.

Problem 4

(C) 9. Since 45=5×945 = 5 \times 9 and gcd⁡(5,9)=1\gcd(5, 9) = 1, we find N mod 5N \bmod 5 and N mod 9N \bmod 9. The units digit of NN is 44, so N≡4(mod5)N \equiv 4 \pmod{5}. Modulo 99, a number is congruent to its digit sum, and the digit sum of NN is the sum of the digit sums of the numbers written down. Since each of these is congruent to the number itself modulo 99,

N≡1+2+⋯+44=44×452=990≡0(mod9).N \equiv 1 + 2 + \cdots + 44 = \frac{44 \times 45}{2} = 990 \equiv 0 \pmod{9}.

The multiples of 99 below 4545 are 0,9,18,27,360, 9, 18, 27, 36, and only 9≡4(mod5)9 \equiv 4 \pmod{5}. By the Chinese Remainder Theorem, N≡9(mod45)N \equiv 9 \pmod{45}.

Problem 5

(C) 157. Let nn be the number of students, so n≡1(mod4)n \equiv 1 \pmod{4}, n≡2(mod5)n \equiv 2 \pmod{5}, and n≡3(mod7)n \equiv 3 \pmod{7}. The numbers ≡3(mod7)\equiv 3 \pmod{7} that are also ≡2(mod5)\equiv 2 \pmod{5} are 17,52,87,…17, 52, 87, \ldots, i.e., n≡17(mod35)n \equiv 17 \pmod{35}. Among 17,52,87,122,15717, 52, 87, 122, 157, the only one ≡1(mod4)\equiv 1 \pmod{4} is 157157. By the Chinese Remainder Theorem, the solution is unique modulo 140140, so 157157 is the only answer between 100100 and 200200.