Modular Arithmetic in AMC & AIME
Modular Arithmetic in AMC & AIME
Author: For:
freeman66 AoPS
Date:
May 13, 2020
0
11 1
10 2
9 3
8 4
7 5
6
”I have a truly marvelous demonstration of this proposition which this margin is too narrow to contain.” -
Pierre de Fermat
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Contents
0 Acknowledgements 3
1 Introduction 4
1.1 Number Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Bases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 Divisibility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Introduction to Modular Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2 Modular Congruences 7
2.1 Congruences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Fermat’s Little Theorem and Euler’s Totient Theorem . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3 Residues 10
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.2 Residue Classes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3.3 Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
7 Problems 29
2
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
§0 Acknowledgements
This was made for the Art of Problem Solving Community out there! I would like to thank Evan Chen for his
evan.sty code. In addition, all problems in the handout were either copied from the Art of Problem Solving
Wiki or made by myself.
He also helped me with the hint formatting. I do honestly think that Evan is a LATEXgod!
And finally, please do not make any copies of this document without referencing this original one. At least cite
me when you are using this document.
3
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
§1 Introduction
§1.1 Number Theory
Number theory deals with the properties and relationships between numbers, especially positive integers.
Definition 1.1 (Prime & Composite) — If an integer has no positive divisors other than 1 and itself, it is
said to be prime; otherwise, it is said to be composite. Note that 1 is considered composite.
Definition 1.2 (Multiples & Factors) — An integer a is said to be a multiple of another integer b if there
exists an integer k such that a = kb. The integer b here is said to be called a factor or a divisor of a.
Definition 1.3 (Prime Factorization) — Any integer N can be written as the product of the primes it is
divisible by. The prime factorization of N is
Y
N= pei = 2e1 · 3e2 · 5e3 · . . . ,
p∈P
where P is the set of positive primes and {ei } is a sequence of integers determining how many times the ith
prime number can be divided out of N . For example, 144 = 22 · 32 and 35 = 51 · 71 .
§1.2 Bases
To understand the notion of base numbers, we look at our own number system. We use the decimal, or
base-10, number system. To help explain what this means, consider the number 2746. This number can be
rewritten as 123410 = 1 · 103 + 2 · 102 + 3 · 101 + 4 · 100 .
Note that each number in 1234 is actually just a placeholder which shows how many of a certain power of 10
there are. The first digit to the left of the decimal place (recall that the decimal place is to the right of the 6, i.e.
2746.0) tells us that there are six 100 ’s, the second digit tells us there are four 101 ’s, the third digit tells us there
are seven 102 ’s, and the fourth digit tells us there are two 103 ’s.
Base-10 uses digits 0-9. Usually, the base, or radix, of a number is denoted as a subscript written at the right
end of the number (e.g. in our example above, 274610 , 10 is the radix).
To learn how to convert bases, read this.
§1.3 Divisibility
Let us first formally define divisibility.
Definition 1.4 (Divisibility) — Let a, b ∈ Z. We say that b divides a if there exists an integer k such that
a = kb. The number b is called a divisor or factor of a, and the number a is called a multiple of b. We
write b|a to denote that b divides a.
Proof. First, note that if a = 0, then q = 0, r = 0 is the unique solution to the equation given.
4
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Definition 1.6 (Quotient & Remainder) — Let a, b ∈ Z, with b 6= 0 and let q, r be numbers such that
a = qb + r, where r < b. We say that q is the quotient of a divided by b, and the r is the remainder of a
divided by b.
Definition 1.7 (Greatest Common Divisor) — Let a, b ∈ Z. An integer d is called a greatest common divisor
of a, b, frequently abbreviated as a gcd of a, b if the following two conditions are met:
Proof. First, if both a and b are 0, then 0 is a gcd for a and b, since 0 is divisible by q for every q ∈ Z.
If a is negative, we can replace a with −a without impacting the divisibility properties of a. Likewise, if b is
negative, we can replace it with −b. Hence, we may proceed assuming that both a and b are nonnegative, and at
least one of a, b is nonzero. Wolog, suppose that a 6= 0.
Define X = {n ∈ N | n = au + bv for some u, v ∈ Z}. Notice that a = a · 1 + b · 0 and a > 0, so a ∈ X.
Therefore, X 6= ∅, and X is a subset of N, so by the Well Ordering Principle X has a minimum. Let d = min(X).
Claim 1. d|a.
5
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Proof of Claim 1. By the Division Theorem, there exist unique q, r ∈ Z such that a = qd + r, and
0 ≤ r < d. Moreover, as d ∈ X, there exist u, v ∈ Z such that d = au + bv. Hence, we have
r = a − qd
= a − q(au + bv)
= (1 − qu)a + (−qv)b.
Hence, if r > 0, we must have r ∈ X. However, since r < d, we cannot have r ∈ X, since d = min(X).
Therefore, r = 0, so a = qd and d|a.
Claim 2. d|b.
Hence, we have that d is a common divisor to both a and b. It remains to establish the second property for a
gcd, namely, that if q|a and q|b, we also have q|d.
To that end, suppose that q is a common divisor of a and b, so that there exist integers k, ` such that a = kq
and b = `q. Then we have
d = au + bv = kqu + `qv = q(ku + `v),
and thus q|d.
Therefore, d meets the definition of a gcd for a, b, and thus a gcd must exist.
• gcd(a, 0) = a.
• gcd(a, 1) = 1.
Definition 1.10 (Least Common Multiple) — The least common multiple of two numbers a, b is, like
the greatest common factor, defined by its name. It is the smallest multiple m in which a|m and b|m.
Definition 1.12 (Coprime) — Let a, b ∈ Z. We say that a and b are coprime, if a and b share no common
factors. That is to say, a and b are coprime if gcd(a, b) = 1. We write a ⊥ b to denote that a and b are
coprime.
6
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
• a
d and b
d are coprime.
Remark 1.14. When learning a new topic, try to find the motivation behind every idea. This will allow you to
realize when to use what idea!
Example 1.15
Suppose it is 1 : 00 now. What time will it be exactly 1000 hours from now?
Solution. The key to solving this problem is realizing that the times will repeat themselves every 12 hours. In
other words, the time will be 1 : 00 whenever the number of hours from now is a multiple of 12.
What is the multiple of 12 that is closest to 1000? After some experimentation, we see that the closest multiple
is 996, so 996 hours from now it will be 1 : 00 as well. Thus, exactly 1000 hours from now the time will be
5 : 00 .
For example, because 4, 16, 1000, and 4252 all share the same remainder when divided by 12, the following
equation is valid:
4 ≡ 16 ≡ 1000 ≡ 4252 (mod 12).
§2 Modular Congruences
Let us start with a problem involving congruences:
Example 2.1
We have a clock with six numbers on its face: 0, 1, 2, 3, 4, and 5. The clock only hand moves clockwise from
0 to 1 to 2 to 3 to 4 to 5 and back again to 0.
7
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Solution. We start by listing the first 30 numbers in the list and the first 30 positive integers side by side:
1 2 3 4 5 0 1 2 3 4 5 6
1 2 3 4 5 0 7 8 9 10 11 12
1 2 3 4 5 0 13 14 15 16 17 18
1 2 3 4 5 0 19 20 21 22 23 24
1 2 3 4 5 0 25 26 27 28 29 30
We can see that the answers to parts 1 and 2 are 0 and 4, respectively. We can also notice that each number on
the left grid is the remainder of each number on the right grid when divided by 6. Hence, we see that the answer
to part 3 is the remainder when 42 ÷ 6, which is 0, and that the answer to part 4 is 1337 ÷ 6, which is 5.
§2.1 Congruences
Definition 2.2 (Congruence) — Two integers are said to be equivalent (or congruent) modulo a if their
difference is a multiple of a.
We shorten ”modulo” to ”mod”, and use the symbol ≡ to denote congruence. For example,
For integers x and y, y ≡ x (mod a) if and only if m | x − y. Hence, for an integer z, we have x − y = za.
Isolating z gives us z = x−y
a . If z is an integer, then y ≡ x (mod a).
x = z1 a + w, and
y = z2 a + w,
Example 2.4
How many positive integers less than 12 are relatively prime to 12?
What if we replaced 12 with 100? Or what if we used 10000? That would take a very long time. So instead
we use Euler’s totient function:
Definition 2.5 (Euler’s Totient Function) — The totient function φ(n) is defined as the number of positive
integers less than n that are relatively prime to n.
Remark 2.6. Definitions are very important. If we had defined it by the theorem, it would be so much harder to
relate it to relatively prime. There also would have been no motivation for this idea.
8
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
• For prime p, φ(p) = p − 1, because all numbers less than p are relatively prime to it.
• In fact, we also have for any a, b that φ(a)φ(b) gcd(a, b) = φ(ab)φ(gcd(a, b)).
There isn’t much to learn about the Totient Function, since it appears very rarely. Let us turn to its relation
with modular arithmetic. There are always the problems that ask for the last two/three/four/etc. digits of
some large operation (for example, 10243 . Even using a calculator won’t help. So instead, we use the following
methods:
Remark 2.9. However, remember: only use powerful techniques when you have to. If the problem is find the last
digit of 24 , the following methods will be overkill.
Example 2.10
Find the remainder when 2304 is divided by 7.
26 ≡ 1 (mod 7).
Note that
2304 = 2300 · 24 = (26 )50 · 24 ,
so
(26 )50 · 24 ≡ 150 · 16 ≡ 16 ≡ 2 (mod 7).
Notice how Fermat’s Little Theorem doesn’t directly answer the problem, but by taking out all the 26 s, we were
able to get our answer. However, this leaves us with an issue - what if the modulo isn’t prime? For example, to
find the last digit, we have to take mod 10, but 10 isn’t prime. How can we solve the problem?
9
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Remark 2.12. Notice that this is a generalized form of Fermat’s Little Theorem.
Example 2.13
Find the last two digits of 383 .
Solution. We know that this is the same as taking mod 100. Using Euler’s Totient Theorem with a = 3 and
n = 100, we get
3φ(100) ≡ 1 (mod 100).
Using the formula for finding φ(n), we get φ(100) = 40. Thus,
Notice that
383 = 380 · 33 = (340 )2 · 33 ,
so
(340 )2 · 33 ≡ 12 · 27 ≡ 27 (mod 100),
so the last two digits are 27.
§2.3 Exercises
Exercise 2.14. How many numbers under 1000 are relatively prime to 1000?
Exercise 2.17. Find the last two digits of 640 + 840 . (Note: this question is hard! You cannot apply any of
the theorems listed above on your first step, since 6 and 8 are not relatively prime to 100)
Exercise 2.19. Jimmy takes a one digit number to the fourth power and the last digit is 1. He takes it to
the fifth power and the last digit is 3. What is his number?
§3 Residues
§3.1 Introduction
We say that b is the modulo-a residue of c when c ≡ b (mod a), and 0 ≤ b < a.
10
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Example 3.1
List the integers between -70 and 70 whose modulo 12 residues are 10.
Solution. An integer is congruent to 10 mod 12 if it can be written as 12a + 10 for any integer a. This gives us
the inequality
−70 < 12a + 10 < 70.
Subtracting 10 from all sides gives us
−80 < 12n < 60,
and dividing by 12 gives
2
−6 < n < 5.
3
Thus, we have
n = −6 : 12(−6) + 10 = −62
n = −5 : 12(−5) + 10 = −50
n = −4 : 12(−4) + 10 = −38
n = −3 : 12(−3) + 10 = −26
n = −2 : 12(−2) + 10 = −14
n = −1 : 12(−1) + 10 = −2
n = 0: 12(0) + 10 = 10
n = 1: 12(1) + 10 = 22
n = 2: 12(2) + 10 = 34
n = 3: 12(3) + 10 = 46
n = 4: 12(3) + 10 = 58
Hence, all integers b such that −70 < b < 70 and b ≡ 10 (mod 12) are
{−62, −50, −38, −26, −14, −2, 10, 22, 34, 46, 58}.
Definition 3.2 (Residue Class) — The integers congruent to x (mod a) are known as a residue class.
(Residue classes are also known as equivalence classes or congruence classes.)
For example, {−62, −50, −38, −26, −14, −2, 10, 22, 34, 46, 58} is a residue class of 10 (mod 12).
§3.3 Exercises
11
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
1. 11
2. 45
3. 23
4. 434
5. 42
6. 1337
Exercise 3.4. Write each of the following integers in the form 3a + b, where a and b are integers and
0 ≤ b < 3.
1. 43
2. 4
3. 100
4. 98
5. 42
6. -34
7. 1337
Exercise 3.5. Show that if x ≡ y (mod a) and y ≡ z (mod a), then x ≡ z (mod a).
a1 ≡ a2 (mod n)
b1 ≡ b2 (mod n).
We can add these, and get
a1 + b1 ≡ a2 + b2 (mod n).
12
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Exercise 4.3. Let a, b, and c be integers whose residues modulo 8 are 4, 5, and 7, respectively. Compute
the residue of a + b + c (mod 8).
a ≡ b (mod m)
c ≡ d (mod m),
then
ac ≡ bd (mod m).
13
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Exercise 4.7. The residues of 3 positive integers modulo 8 are 1, 4, and 7. Find the residue of their products
modulo 8.
ac ≡ bc (mod m).
Proof. We have a · a ≡ b · b (mod m) =⇒ a2 ≡ b2 (mod m). We can multiply factors of a and b to powers of a
and b to show that the next highest power of a and b are also congruent.
a · a2 ≡ b · b2 (mod m) =⇒ a3 ≡ b3 (mod m)
a · a3 ≡ b · b3 (mod m) =⇒ a4 ≡ b4 (mod m)
a · a4 ≡ b · b4 (mod m) =⇒ a5 ≡ b5 (mod m)
a · a5 ≡ b · b5 (mod m) =⇒ a6 ≡ b6 (mod m)
·
·
·
a · ac−1 ≡ b · bc−1 (mod m) =⇒ ac ≡ bc (mod m)
Definition 4.11 (Modular Inverse) — The multiplicative inverse of an integer a (mod m) is the integer
14
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Example 4.12
Find the inverses of all mod 12 residues that have inverses.
Proof. If a−1 exist, it is a solution to the congruence ax ≡ 1 (mod n). Thus, for some value of x,
ax − yn = 1,
where y is an integer. We let z = gcd(a, n), which means that z | ax and z | yn. A divisor of two integers is the
divisor of their difference, which means that z | (ax − yn). Since ax − yn = 1, z | 1. The only integer that is a
divisor of 1 is 1, so z = 1. Therefore, a−1 exists if gcd(a, n) = 1.
Exercise 4.15. Find all possible residues modulo 20 that have inverses.
From the exercise above, it is pretty hard to find modular inverses. So how can we speed up the process?
Let’s start with an example:
Example 4.16
Find the inverse of 3 modulo 7.
15
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Solution. We list the first few integers that are congruent to 1 (mod 7). They are
8, 15, 22, 29, . . .
The term 15 is of the form 3x, where x = 5. Thus, the inverse of 3 modulo 7 is 5 .
This method seems rather tedious for larger moduli and inverses - we need a systematic way to find inverses.
Proof. Let a, b, q, r be as in the statement of the theorem. Let d = gcd(a, b). Notice that as r = a − bq, and
both a and b are divisible by d, then r is divisible by d as well.
Moreover, suppose that d0 is an integer such that d0 |r and d0 |b. Then since a = qb + r, we must also have that
d0 |a. But then as d = gcd(a, b), we have that d0 |d. Hence, any divisor of both r and b is also a divisor of d.
Therefore, d meets the definition of gcd for b and r. By uniqueness of the positive gcd, we therefore have that
d = gcd(b, r).
Example 4.18
Find the inverse of 37 modulo 97.
Solution. We turn this into the equation 37x + 97y = 1, and solve for x. Then, we divide 97 ÷ 37 to get a
quotient of 2 and a remainder of 23. We compute 37 ÷ 23, and get a quotient of 1 and a remainder of 14. Next,
we compute 23 ÷ 14, and we get a quotient of 1 and remainder 9. Dividing 14 ÷ 9, we get quotient 1 and
remainder 5. 9 ÷ 5 has a quotient of 2 and a remainder of 4. Finally, 5 ÷ 4 has a quotient 1 and remainder 1.
From this we get the equations:
97 = 2 · 37 + 23
37 = 1 · 23 + 14
23 = 1 · 14 + 9
14 = 1 · 9 + 5
9=1·5+4
5 = 1 · 4 + 1.
16
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
23 = 97 − 2 · 37
14 = 37 − 1 · 23
9 = 23 − 1 · 14
5 = 14 − 1 · 9
4=9−1·5
1 = 5 − 1 · 4.
Substituting, we have:
1=5−1·4
= 5 − (9 − 1 · 5)
=2·5−9
= 2(14 − 1 · 9) − 9
= 2 · 14 − 3 · 9
= 2 · 14 − 3(23 − 1 · 14)
= 5 · 14 − 3 · 23
= 5(37 − 1 · 23) − 3 · 23
= 5 · 37 − 8 · 23
= 5 · 37 − 8(97 − 2 · 37)
= −8 · 97 + 21 · 37.
Hence, x = 21, which means that the inverse of 37 modulo 97 is 21 , or 21 · 37 ≡ 1 (mod 97).
Definition 5.1 (Linear Congruence Equation) — A linear congruence equation is a congruence that has
a variable raised only to the first power.
ax ≡ b (mod n),
17
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Example 5.3
Find the values of x where 0 ≤ x < 5 that satisfy the following linear congruences:
1. x − 4 ≡ 0 (mod 5).
2. x − 1 ≡ 1 (mod 5).
3. x + 3 ≡ 1 (mod 5).
4. x + 12 ≡ 3 (mod 5).
1. Since addition is a valid operation in modular arithmetic, we can add 4 to both sides. Thus, we have
x − 4 + 4 ≡ 0 + 4 (mod 5) =⇒ x ≡ 4 (mod 5).
2. As before, we add 1 to both sides of the congruence, which gives x ≡ 2 (mod 5).
3. Since subtraction is a valid operation in modular arithmetic, we can subtract 3 from both sides. Thus, we
have x ≡ −2 ≡ 3 (mod 5).
Example 5.4
Find the values of x where 0 ≤ x < 5 that satisfy the following linear congruences:
1. 3x ≡ 1 (mod 5).
2. 3x ≡ 2 (mod 5).
3. 2x ≡ 3 (mod 5).
5. 2x − 4 ≡ 2 (mod 5).
1. We can’t divide both sides by 4, because there is no law of division in modular arithmetic. However, we
can multiply by the modular inverse of 3 (mod 5), which is 2. Multiplying, we have 6x ≡ 2 (mod 5). Since
6 ≡ 1 (mod 5), we have 6x ≡ 1x ≡ x (mod 5). Thus, we have x ≡ 2 (mod 5).
2. In this part, we again multiply 3x ≡ 2 (mod 5) by 3−1 , which is 2. Thus, we have 6x ≡ 4 (mod 5) =⇒
x ≡ 4 (mod 5).
18
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
2x − 4 + 4 ≡ 2 + 4 (mod 5)
2x ≡ 6 (mod 5)
2x ≡ 1 (mod 5).
From these examples, we see that if the coefficient of the variable is relatively prime to the modulus, then we can
get rid of the coefficient by multiplying both sides of the congruence by the inverse of the coefficient.
Exercise 5.5. Find all possible values of x such that 23x ≡ 14 (mod 15).
Exercise 5.6. Find all possible values of x such that 23x + 234 ≡ 12 (mod 15).
Exercise 5.7 (Introduction to Number Theory). Let y be a positive integer. Prove that if ay ≡ by
(mod my) for integers a and b, then a ≡ b (mod m).
Example 5.8
Find all x such that
x≡0 (mod 2)
x≡0 (mod 5).
Solution. From the first congruence, we see that x is divisible by 2. From the second, we see that x is also
divisible by 5. Thus x is divisible by 10, or x ≡ 0 (mod 10) .
Example 5.9
Find all possible values of x such that
x≡1 (mod 3)
x≡0 (mod 7)
Solution. From the second congruence, we see that x is divisible by 7. We list the first few nonnegative multiples
of 7.
7, 14, 21, 28, 35, 42, 49, 56, 63, 70, . . .
We now list all integers in that list that have a remainder of 1 when divided by 3. They are
19
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
All these terms differ by lcm[3, 7], or 21. Thus x ≡ 7 (mod 21).
However, we are guessing this is the solution. We write x ≡ 7 (mod 21) algebraically as
x = 21y + 7
where y is an integer. Since 21y + 7 ≡ 0 (mod 7) and 21y + 7 ≡ 1 (mod 3), we see that
Example 5.10
Find all x such that
x≡3 (mod 4)
x≡2 (mod 7).
Solution. This problem would be hard to solve using the method in the previous problem. We need a systematic
way to solve this.
The first congruence tell us that x ≡ 3 (mod 4). We write this algebraically as
x = 4a + 3,
where a is an integer.
The second congruence tells us that x ≡ 2 (mod 7). We write this algebraically as
x = 7b + 2,
where b is an integer.
Thus, we have to system of equations:
x = 4a + 3 = 7b + 2.
We rearrange the equation as 4a + 1 = 7b, and mod 7 to get
4a + 1 ≡ 0 (mod 7).
We multiply the congruence by the inverse of 4 (mod 7), which is 2. Thus, we have
4a ≡ 6 (mod 7)
2 × 4a ≡ 2 × 6 (mod 7)
8a ≡ 12 (mod 7)
8a ≡ 5 (mod 7)
1a ≡ 5 (mod 7)
a≡5 (mod 7).
We substitute a = 5 into the equation x = 4a + 3 = 7b + 2, and get x = 23. However this is not the only solution,
because we expect the solution to be a congruence.
20
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Since
23 ≡ 3 (mod 4)
23 ≡ 2 (mod 7)
x − 23 ≡ 3 − 3 ≡ 0 (mod 4)
x − 23 ≡ 2 − 2 ≡ 0 (mod 7).
From this, we see that x − 23 is divisible by both 4 and 7, which are relatively prime, so x − 23 ≡ 0 (mod 28).
Thus, all values of x that satisfy the congruence are
x ≡ 23 (mod 28) .
Example 5.11
Find all x such that
x≡1 (mod 2)
x≡2 (mod 3)
x≡0 (mod 5).
Solution. We know that the solution to a system of two linear congruences is another congruence. If we take
two congruences and solve them, we get a single congruence. We can then combine this congruence with the
third remaining congruence, thus solving the whole system.
We begin by finding all x such that
x≡1 (mod 2)
x≡2 (mod 3).
x = 2a + 1 = 3x + 2.
2a − 1 ≡ 0 (mod 3).
We solve for a in this congruence by adding 1 to both sides and multiplying by the inverse of 2 (mod 3), which
is 2. Thus, we have
2a − 1 ≡ 0 (mod 3)
2a ≡ 1 (mod 3)
2 × 2a ≡ 2 × 1 (mod 3)
4a ≡ 2 (mod 3)
1a ≡ 2 (mod 3)
a≡2 (mod 3).
21
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
5≡1 (mod 2)
5≡2 (mod 3).
x−5≡1−1≡0 (mod 2)
x−5≡2−2≡0 (mod 3).
x≡5 (mod 6)
x≡0 (mod 5).
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, . . .
We see that 5, 35, 65 · · · are congruent to 5 (mod 6). These differ by 30, so we see that x ≡ 5 (mod 30). However,
we need to check our solution. Writing x ≡ 5 (mod 3)0 into an algebraic form (x = 30a + 5), and taking the
mod 5 and mod 6, we have
30a + 5 ≡ 0 (mod 5)
30a + 5 ≡ 5 (mod 6).
x≡1 (mod 2)
x≡2 (mod 3)
x≡0 (mod 5).
are
x≡5 (mod 30).
Example 5.12
Mr. Yu wants to divide the class into groups. When he tries to divide into groups of 3, 1 student is left over.
When he tries to divide into groups of 4, 1 student is left over. And when he tries to divide into groups of 5,
1 student is left over. What is the least number of students he could have, assuming he has more than 1
student?
22
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Solution. We simply write these equations in terms of mods. If the number of students he has is n, then
In general, we have
Example 5.15
Find all integers x such that
x = 10a + 1 = 12b + 4.
23
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
We can see that the GCD of the first 3 systems moduli are relatively prime, and the fourth are not. This gives
the following result:
x ≡ a (mod m),
x ≡ b (mod n)
always has a solution in integers x. Furthermore, the solution is of the form x ≡ c (mod mn).
x≡3 (mod 4)
x≡5 (mod 9).
x−3≡4 (mod 2)
4x + 2 ≡ 0 (mod 5).
Exercise 5.19. Find the smallest possible positive value of n such that
n≡4 (mod 5)
n≡3 (mod 6)
n≡2 (mod 7).
24
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Example 6.1
A quick refresher:
(a) What are the remainders when 3333 + 4444 and 3333 · 4444 are divided by 5?
Example 6.2
What are the last two digits of the integer 17198 ?
Solution. Note that 172 ≡ 289 ≡ −11 (mod 100). Thus, the problem is simplified to computing (−11)99 ≡ −1199
(mod 100). Now note that by the Binomial Theorem
99 99 99 99 2 99
11 = (10 + 1) = 10 + · · · + 10 + 101 + 1.
2 1
When this expansionis reduced modulo 100, all but the last two terms will go away since they are all divisible
by 100, so 1199 ≡ 99
1 · 10 + 1 ≡ 91 (mod 100). As a result, 17
198 ≡ −91 ≡ 09 (mod 100).
Remark 6.3. There are some instances where modular division works. Don’t count on it all the time, however.
Example 6.4
A few proofs:
(a) Prove that any integer is divisible by 2n iff the integer formed by its last n digits is also divisible by 2n .
(b) Let N = a0 a1 a2 . . . an be an integer. (The bar above the previous expression suggests the variables
are digits and that we are not multiplying them together.) Prove that N is divisible by 9 iff
a0 + a1 + a2 + · · · + an
is also divisible by 9.
Solution. (a) Let Y be the integer formed by the last n digits and let X be the integer formed by the digits to
the left of these n digits. For example, in the 124564 case above, X = 1245 and Y = 64. Note that the
integer can thus be written as 10n X + Y . Now note that 10n ≡ (2n )(5n ) ≡ 0 (mod 2n ), so 10n X + Y ≡ Y
(mod 2n ). This immediately implies the conclusion.
25
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
We attempt to simplify this modulo 9. The key here is to note that 10 ≡ 1 (mod 9). This further implies
that 102 ≡ 1 (mod 9), 103 ≡ 1 (mod 9), and so on. Making all the necessary substitutions gives
N ≡ a0 + a1 + a2 + · · · + an (mod 9).
Thus N and the sum of the digits of N give the same remainder upon division by 9, implying the conclusion.
Example 6.5
I am thinking of a number. All I can give to you is that if you triple my number, it leaves a remainder
of 13 when divided by 17. Unfortunately, this is clearly not enough information to figure out my number.
However, it is enough information to figure out what the remainder of my original number is when divided
by 17. What is this remainder?
17+13
Solution. A one-line solution: 3 = 10.
Example 6.6
Find the remainder when 515 is divided by 128.
Example 6.7
Find the remainder when 129 is divided by 1000.
129 ≡ (1728)3 ≡ (−272)3 ≡ 984 · (−272) ≡ (−16) · (−272) ≡ 352 (mod 1000).
Example 6.8
Calculate gcd(67620, 66234).
Solution. This looks atrocious, but it’s not really. First, we can write
Therefore, by the Euclidean Algorithm, we have that gcd(67620, 66234) = gcd(66234, 1386).
26
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
• Each number (since the second) is obtained by adding 9 to the number before in the list.
Solution. Notice that they all are of the same residue modulo 9. Thus,
7 + 4 + A + 5 + 2 + B + 1 ≡ A + B + 19 ≡ A + B + 1 (mod 3),
Solution. Factor to get d = (ab − 7c)(ab + 7c). Observe that d is prime, so we must have ab − 7c = 1. By trial
and error, we find that (a, b, c, d) = (3, 5, 2, 29) works, so our answer is 3 + 5 + 2 = 10 .
27
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Remark 6.15. A common strategy is to split up the primes of the modulo, i.e.
where Y
N= pei = 2e1 · 3e2 · 5e3 · . . . .
p∈P
28
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Example 6.16
Prove that every year, including any leap year, has at least one Friday 13-th.
Solution. It is enough to prove that each year has a Sunday the 1st. Now, the first day of a month in each year
falls in one of the following days:
(The above table means that, depending on whether the year is a leap year or not, that March 1st is the 50th or
51st day of the year, etc.) Now, each remainder class modulo 7 is represented in the third column, thus each
year, whether leap or not, has at least one Sunday the 1st.
§7 Problems
Problem 7.1 (AIME I 2010). Find the remainder when 9 × 99 × 999 × · · · × 99 · · · 9} is divided by 1000.
| {z
999 9’s
Problem 7.2 (AMC 10 B 2010). Positive integers a, b, and c are randomly and independently selected with
replacement from the set {1, 2, 3, . . . , 2010}. What is the probability that abc + ab + a is divisible by 3?
Problem 7.3 (AMC 12 A 2010). The number obtained from the last two nonzero digits of 90! is equal to n.
What is n?
Problem 7.4 (AHSME 1995). Consider the triangular array of numbers with 0,1,2,3,... along the sides and
interior numbers obtained by adding the two adjacent numbers in the previous row. Rows 1 through 6 are
shown.
0
1 1
2 2 2
3 4 4 3
4 7 8 7 4
5 11 15 15 11 5
Let f (n) denote the sum of the numbers in row n. What is the remainder when f (100) is divided by 100?
Problem 7.5 (AMC 8 1999). What is the remainder when 19992000 is divided by 5?
Problem 7.6 (AMC 10 B 2009). What is the remainder when 30 + 31 + 32 + . . . + 32009 is divided by 8?
29
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
Problem 7.8 (USAJMO 2013). Are there integers a and b such that a5 b + 3 and ab5 + 3 are both perfect cubes
of integers?
30
freeman66 (May 13, 2020) Modular Arithmetic in the AMC and AIME
List of Definitions
31