This note continues the Divisibility note. As before, all variables are integers unless otherwise specified, and the modulus m is always a positive integer.
Definitions and Basic Properties
Definition 1 (Congruence).
Let a,b∈Z and m∈N.. We say a is congruent to bmodulom and write a≡b(modm) if m∣(b−a),, in other words, b−a=mk for some k∈Z.. The integer m is called the modulus. If m∤(b−a),, we write a≡b(modm)..
Symbolically,
a≡b(modm)⇔(∃k∈Z)(b−a=mk).
For example, 17≡2(mod5) because 2−17=−15=5×(−3),, and −1≡9(mod10) because 9−(−1)=10..
Recall the division algorithm: for every n∈Z there are unique integers q and r such that n=qm+r and 0≤r<m.. We call r the remainder of n modulo m and write r=nmodm.. Since r−n=−qm,, we have n≡r(modm);; that is, every integer is congruent to exactly one of 0,1,…,m−1.. Moreover,
a≡b(modm)⇔amodm=bmodm,
so two integers are congruent modulo m precisely when they leave the same remainder upon division by m..
Basic Properties.
(Reflexivity)a≡a(modm)..
(Proof: a−a=0=m×0.).)
(Symmetry) If a≡b(modm),, then b≡a(modm)..
(Proof: If b−a=mk,, then a−b=m(−k).).)
(Transitivity) If a≡b(modm) and b≡c(modm),, then a≡c(modm)..
(Proof: Write b−a=mk1 and c−b=mk2.. Then c−a=(c−b)+(b−a)=m(k1+k2).).)
(Addition and Subtraction) If a1≡a2(modm) and b1≡b2(modm),, then a1±b1≡a2±b2(modm)..
(Proof: (a2±b2)−(a1±b1)=(a2−a1)±(b2−b1),, and m divides both terms.)
(Multiplication) If a1≡a2(modm) and b1≡b2(modm),, then a1b1≡a2b2(modm)..
(Proof: a2b2−a1b1=a2(b2−b1)+b1(a2−a1),, and m divides both terms.)
(Powers) If a≡b(modm),, then ak≡bk(modm) for every non-negative integer k..
(Proof: Apply (e) repeatedly, i.e., by induction on k.).)
In other words, one can add, subtract, or multiply two congruences with the same modulus, exactly as with ordinary equations. When computing modulo m,, 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),, but 3≡8(mod10).. One cannot cancel the factor 2 because gcd(2,10)=1..
Example 2.
Find the remainder when 2100 is divided by 7..
Solution
Since 23=8≡1(mod7),, property (f) gives 299=(23)33≡133=1(mod7).. By property (e), 2100=2×299≡2×1=2(mod7).. The remainder is 2..
Divisibility Criteria
In this section, we use the basic properties of congruence to explain the divisibility criteria for 2,,3,,4,,5,,9,, and 11.. Throughout, a positive integer n is written in terms of its decimal digits a0,a1,…,ak∈{0,1,…,9} as
n=i=0∑kai×10i=ak×10k+⋯+a1×10+a0.
Divisibility by 2. Write n=10a+b,, where b=a0 is the units digit. Since 10≡0(mod2),, we have 10a+b≡b(mod2).. Hence the divisibility of n by 2 depends only on the units digit.
Divisibility by 3. Since 10≡1(mod3),, we have 10i≡1(mod3) for every non-negative integer i.. It follows that
i=0∑kai×10i≡i=0∑kai(mod3).
That is, n is congruent to its digit sum modulo 3..
Divisibility by 4. Write n=100a+b,, where b=10a1+a0 is the number formed by the last two digits. Since 100=4×25≡0(mod4),, we have 100a+b≡b(mod4).. Hence the divisibility of n by 4 depends only on the last two digits.
Divisibility by 5. Write n=10a+b,, where b=a0 is the units digit. Since 10≡0(mod5),, we have 10a+b≡b(mod5).. Hence the divisibility of n by 5 depends only on the units digit.
Divisibility by 9. Since 10≡1(mod9),, we have 10i≡1(mod9) for every non-negative integer i.. It follows that
i=0∑kai×10i≡i=0∑kai(mod9).
That is, n is congruent to its digit sum modulo 9..
Divisibility by 11. Since 10≡−1(mod11),, we have 10i≡(−1)i(mod11) for every non-negative integer i.. It follows that
That is, n is congruent modulo 11 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 n is divisible by m=2,,3,,4,,5,,9,, or 11;; they also tell us how to find the remainder nmodm efficiently.
Example 3.
Let n=8,675,309.. Its digit sum is 8+6+7+5+3+0+9=38,, so n≡38≡2(mod9) and n≡38≡2(mod3).. Its alternating digit sum, starting from the units digit, is 9−0+3−5+7−6+8=16,, so n≡16≡5(mod11).. Its last two digits form 09≡1(mod4),, so n≡1(mod4)..
Exercise 4.
Without performing long division, find the remainder when
1,234,567 is divided by 9;;
918,082 is divided by 11;;
250×1050+7 is divided by 4..
Hint: For (c), first find the last two digits of the number.
Exercise 5.
Find the digit d such that the four-digit number 3d48 is divisible by 36..
Hint: Since 36=4×9 and gcd(4,9)=1,, a number is divisible by 36 if and only if it is divisible by both 4 and 9 (see Proposition 23 of the Divisibility note).
Exercise 6.
Let N=abc be a three-digit number and let N′=cba be the number obtained by reversing its digits. Prove that 99∣(N−N′)..
Hint: Show that N≡N′(mod9) and N≡N′(mod11),, then use gcd(9,11)=1..
Answers
4. (a) The digit sum is 28≡1(mod9),, so the remainder is 1.. (b) The alternating digit sum is 2−8+0−8+1−9=−22≡0(mod11),, so the remainder is 0.. (c) 250×1050 is a multiple of 100,, so the number ends in 07;; since 7≡3(mod4),, the remainder is 3..
5. The last two digits 48=4×12,, so the number is always divisible by 4.. For divisibility by 9,, we need 3+d+4+8=15+d≡0(mod9),, so d=3.. Indeed, 3348=36×93..
6. Both N and N′ have digit sum a+b+c,, so N≡N′(mod9).. The alternating digit sums are c−b+a and a−b+c,, which are equal, so N≡N′(mod11).. Since 9∣(N−N′),,11∣(N−N′),, and gcd(9,11)=1,, we conclude 99∣(N−N′).. (Directly: N−N′=99(a−c).).)
Conversion from Decimal to Binary Representation
Every non-negative integer n has a unique binary (base 2)) representation of the form
n=ak×2k+ak−1×2k−1+⋯+a1×2+a0,
where ai∈{0,1} for each i=0,1,…,k.. We write n=(akak−1⋯a1a0)2..
Every term except a0 is a multiple of 2,, so from the basic properties of congruence, n≡a0(mod2).. Since a0∈{0,1},, this means a0=nmod2.. Moreover,
n1:=2n−a0
is an integer, and its binary representation is
n1=ak×2k−1+ak−1×2k−2+⋯+a2×2+a1.
So one can find the next binary digit a1=n1mod2.. Repeating this process gives us the values of a0,a1,…,ak..
Algorithm 7 (Decimal to Binary).
Given a non-negative integer n,, set n0=n.. For i=0,1,2,…,, define
ai=nimod2,ni+1=2ni−ai.
Stop when ni+1=0.. Then n=(akak−1⋯a1a0)2,, where k is the last index computed.
Example 8.
We convert 37 to binary.
i
ni
ai=nimod2
0
37
1
1
18
0
2
9
1
3
4
0
4
2
0
5
1
1
6
0
Reading the digits from bottom to top, 37=(100101)2.. Check: 25+22+20=32+4+1=37..
Exercise 9.
Convert 100 and 255 to binary.
Answer
100=(1100100)2 and 255=(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) and gcd(k,m)=1,, then a≡b(modm)..
Proof.
By assumption, m∣(kb−ka)=k(b−a).. Since gcd(m,k)=1,, Euclid’s Lemma (Proposition 17 of the Divisibility note) gives m∣(b−a),, i.e., a≡b(modm)..
For example, 3×7≡3×2(mod5) since 21−6=15,, and as gcd(3,5)=1 we may cancel the 3 to get 7≡2(mod5).. In the earlier remark, 2×3≡2×8(mod10),, the factor 2 cannot be cancelled because gcd(2,10)=2=1..
Definition 11 (Multiplicative Inverse).
Let a∈Z and m∈N.. A multiplicative inverse of a modulo m is an integer x such that ax≡1(modm).. When it exists, it is unique modulo m (see Proposition 12), and we denote it by a−1..
For example, 3−1≡2(mod5) since 3×2=6≡1(mod5)..
Remark. Do not confuse this with the reciprocal a−1=a1.. The notations are the same, but in the context of congruence, a−1 denotes an integer, determined modulo m..
Proposition 12 (Existence of Multiplicative Inverse).
The multiplicative inverse of a modulo m exists if and only if gcd(a,m)=1.. In that case, it is unique modulo m..
Proof.
Suppose gcd(a,m)=1.. Then there exist integers x and y such that ax+my=1 (see Proposition 4 of the Divisibility note). Reducing modulo m gives ax≡1(modm);; in other words, x is a multiplicative inverse of a modulo m..
Conversely, suppose ax≡1(modm),, say 1−ax=my.. Then ax+my=1,, so every common divisor of a and m divides 1,, hence gcd(a,m)=1..
For uniqueness, if ax≡1≡ax′(modm),, then the Cancellation Law (Proposition 10, with k=a)) gives x≡x′(modm)..
In practice, a−1 is found either by trial for small m (try x=1,2,…,m−1)) or by the Extended Euclidean Algorithm from the Divisibility note, which produces x and y with ax+my=1 directly.
Exercise 13.
For each of the following, determine whether the multiplicative inverse exists. If it does, find it.
4−1(mod9);;
6−1(mod15);;
7−1(mod26);;
10−1(mod35);;
11−1(mod30);;
17−1(mod60)..
Hint: First compute the gcd. For (f), use the Extended Euclidean Algorithm.
Answers
gcd(4,9)=1,, and 4×7=28≡1(mod9),, so 4−1≡7(mod9)..
gcd(6,15)=3=1,, so no inverse exists.
gcd(7,26)=1,, and 7×15=105≡1(mod26),, so 7−1≡15(mod26)..
gcd(10,35)=5=1,, so no inverse exists.
gcd(11,30)=1,, and 11×11=121≡1(mod30),, so 11−1≡11(mod30)..
The Euclidean Algorithm gives 60=3×17+9,,17=1×9+8,,9=1×8+1.. Working backwards,
1=9−8=9−(17−9)=2×9−17=2×(60−3×17)−17=2×60−7×17,
so 17−1≡−7≡53(mod60).. Check: 17×53=901=15×60+1..
With multiplicative inverses, we can now solve linear congruences by “dividing” by a..
Proposition 14.
Let a,b∈Z and m∈N with gcd(a,m)=1.. Then the congruence
ax≡b(modm)
has a solution in x,, and the solution is unique modulo m;; namely, x≡a−1b(modm)..
Proof.
By Proposition 12, a−1 exists. If x≡a−1b(modm),, then ax≡aa−1b≡b(modm),, so x is a solution. Conversely, if ax≡b(modm),, multiplying both sides by a−1 gives x≡a−1ax≡a−1b(modm)..
Remark. If g=gcd(a,m)>1,, the congruence ax≡b(modm) is equivalent to the equation ax+my=b,, which has integer solutions if and only if g∣b (see Proposition 4 of the Divisibility note). For instance, 2x≡3(mod6) has no solution, while 2x≡4(mod6) has the two solutions x≡2 and x≡5(mod6),, so the solution is no longer unique modulo m..
Example 15.
Solve 15x≡23(mod17)..
Solution
Since 17 is prime and 17∤15,, we have gcd(15,17)=1,, so 15−1 exists. We find it using the Extended Euclidean Algorithm:
1715=1×15+2,=7×2+1.
Working backwards,
1=15−7×2=15−7×(17−15)=8×15−7×17,
so 15×8≡1(mod17),, i.e., 15−1≡8(mod17).. Multiplying both sides of the congruence by 8,,
x≡8×23=184=10×17+14≡14(mod17).
Check: 15×14=210=23+187=23+11×17.. Therefore the solutions are exactly the integers x≡14(mod17)..
Chinese Remainder Theorem
Let us begin with a simple observation. Any integer n modulo m=10 has 10 possible remainders 0,1,…,9.. For each of these values, let us compute nmod2 and nmod5..
nmod10
0
1
2
3
4
5
6
7
8
9
nmod2
0
1
0
1
0
1
0
1
0
1
nmod5
0
1
2
3
4
0
1
2
3
4
From the table, we see that each of the 2×5=10 possible pairs (nmod2,nmod5) appears exactly once. Hence the values of nmod2 and nmod5 uniquely determine the value of nmod10.. In other words, if you know the remainder of n modulo 2 and the remainder of n modulo 5,, then you also know the remainder of n modulo 10..
Now, let us consider a similar table below.
nmod12
0
1
2
3
4
5
6
7
8
9
10
11
nmod2
0
1
0
1
0
1
0
1
0
1
0
1
nmod6
0
1
2
3
4
5
0
1
2
3
4
5
This time, nmod2 and nmod6 do not determine the value of nmod12.. For example, n=1 and n=7 give the same pair (1,1).. Meanwhile, half of the 2×6=12 possible pairs, such as (0,1),, never appear at all: since 2∣6,, the remainder modulo 6 already determines the remainder modulo 2.. The difference between the two tables is that gcd(2,5)=1,, while gcd(2,6)=2=1..
Theorem 16 (Chinese Remainder Theorem).
Suppose m1,m2,…,mk are pairwise coprime, i.e., gcd(mi,mj)=1 for i=j.. Then for any integers a1,a2,…,ak,, the following system of congruences has a unique solution modulo m=m1m2⋯mk..
xxx≡a1(modm1),≡a2(modm2),⋮≡ak(modmk).
Proof sketch.
Uniqueness. Suppose x and y are both solutions. Then x≡y(modmi),, i.e., mi∣(x−y),, for every i.. Since the mi are pairwise coprime, repeated application of Proposition 23 of the Divisibility note (if a∣n,,b∣n,, and gcd(a,b)=1,, then ab∣n)) gives m∣(x−y),, i.e., x≡y(modm)..
Existence. Consider the m remainders 0,1,…,m−1,, and send each one to its tuple of remainders (xmodm1,…,xmodmk),, as in the first table above. By uniqueness, no two of them give the same tuple. But there are exactly m1m2⋯mk=m possible tuples, so every tuple, in particular (a1modm1,…,akmodmk),, appears exactly once.
Example 17 (Sunzi Suanjing).
Find all integers x such that
xxx≡2(mod3),≡3(mod5),≡2(mod7).Solution
The moduli 3,,5,,7 are pairwise coprime, so by the Chinese Remainder Theorem there is exactly one solution modulo 105.. The first and third congruences say 3∣(x−2) and 7∣(x−2),, so 21∣(x−2),, i.e., x≡2(mod21).. We list the candidates below 105 and check them modulo 5::
x
2
23
44
65
86
xmod5
2
3
4
0
1
Only x=23 works. Therefore the solutions are exactly the integers x≡23(mod105)..
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) and x≡a2(modm2),, find u,v with m1u+m2v=1;; then x=a2m1u+a1m2v is a solution.
Exercise 18.
Find the smallest positive integer n that leaves a remainder of 1 when divided by 3,, a remainder of 2 when divided by 4,, and a remainder of 3 when divided by 5..
Hint: Notice that n+2 is divisible by 3,,4,, and 5..
Exercise 19.
Show that the system
x≡1(mod4),x≡2(mod6)
has no solution. Why does this not contradict the Chinese Remainder Theorem?
Hint: Consider xmod2..
Answers
18. Since n≡−2(mod3),,n≡−2(mod4),, and n≡−2(mod5),, and 3,,4,,5 are pairwise coprime, we get n≡−2(mod60).. The smallest positive such n is 58..
19. The first congruence forces x to be odd, while the second forces x to be even. There is no contradiction because gcd(4,6)=2=1,, so the theorem does not apply.
Practice Problems
What is the remainder when 1!+2!+3!+⋯+100! is divided by 12??
A school has between 100 and 200 students. When they line up in rows of 4,, one student is left over; in rows of 5,, two are left over; and in rows of 7,, three are left over. How many students are there?
(A)117(B)137(C)157(D)177(E)197
Solutions
Problem 1
(D) 9. For k≥4,,k! contains the factors 3 and 4,, so k!≡0(mod12).. Hence the sum is congruent to 1!+2!+3!=9(mod12)..
Problem 2
(E) 9. We work modulo 10.. Since 72=49≡−1(mod10),, we get 72026=(72)1013≡(−1)1013=−1≡9(mod10)..
Problem 3
(A) 01. We work modulo 100.. Since 35=243≡43(mod100),, we get 310≡432=1849≡49(mod100) and 320≡492=2401≡1(mod100).. Therefore 3100=(320)5≡1(mod100)..
Problem 4
(C) 9. Since 45=5×9 and gcd(5,9)=1,, we find Nmod5 and Nmod9.. The units digit of N is 4,, so N≡4(mod5).. Modulo 9,, a number is congruent to its digit sum, and the digit sum of N is the sum of the digit sums of the numbers written down. Since each of these is congruent to the number itself modulo 9,,
N≡1+2+⋯+44=244×45=990≡0(mod9).
The multiples of 9 below 45 are 0,9,18,27,36,, and only 9≡4(mod5).. By the Chinese Remainder Theorem, N≡9(mod45)..
Problem 5
(C) 157. Let n be the number of students, so n≡1(mod4),,n≡2(mod5),, and n≡3(mod7).. The numbers ≡3(mod7) that are also ≡2(mod5) are 17,52,87,…,, i.e., n≡17(mod35).. Among 17,52,87,122,157,, the only one ≡1(mod4) is 157.. By the Chinese Remainder Theorem, the solution is unique modulo 140,, so 157 is the only answer between 100 and 200..