Modular Arithmetic
Modular Arithmetic
1 Introduction
Modular arithmetic is a topic residing under Number Theory, which roughly speaking is the study of integers and
their properties. Modular arithmetic highlights the power of remainders when solving problems. In this lecture, I
will quickly go over the basics of the subject and then dive into what makes this topic so interesting. (Note that
this lecture will be much more information-loaded than the previous one, in that unlike last time this will probably
be an entirely new concept for most of you.)
• It’s sort of difficult to define integers in themselves, but in this case the Wikipedia definition suffices: “An
integer is a number that can be written without a fractional or decimal component.” Some examples of
integers are 5, −17, and 3628800. It is important to know that while the set of integers is closed1 under
addition, subtraction, or multiplication, it is NOT under division!
• 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 divisor2 of a. Furthermore, a is said to be divisible by b.
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 (with the exception of 1, of course.)
• 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 7! = 24 · 32 · 5 · 7. Prime factorization
often plays a critical role in NT problems, so know it on the back of your hand!
• The greatest common divisor of a set of integers A is the largest positive integer n that divides evenly
into every element in A. For example, gcd(15, 20) = 5 and gcd(12, 18) = 6. Similarly, the least common
multiple of a set of integers B is the smallest positive integer N such that N is evenly divisible by every
integer in B. For example, lcm(15, 20) = 60 and lcm(12, 18) = 36. There are formulae for these, but there is
no need to go into them now.
Solution. The key to solving this problem is realizing that the times will repeat themselves every 12 hours. This
means, for example, that 12 hours from now the time will be 1 : 00, 24 hours from now the time will be 1 : 00, and
so on. We can extrapolate this and say that the time will be 1 : 00 whenever the number of hours from now is a
1 A set A is said to be closed under an operation if said operation takes members from the set to produce a member from that same
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 .
In the above solution, note that the answer to the question depends only on the remainder when 1000 is divided
by 12, which was 4. As a result, the answer would be the same whether we were asking for the time 4 hours from
now, 16 hours from now, 1000 hours from now, or 4252 hours from now.
To make the above reasoning more rigorous, we can group the integers into groups called residue classes
modulo n that have a common remainder when divided by n, and we say two integers are congruent or equivalent
modulo n if they lie in the same residue class. For example, the integers 4, 16, 1000, and 4252 all are congruent
modulo 12 since they share the same remainder when divided by 12.
More formally, we say that a ≡ b (mod n) if a and b fall in the same residue class modulo n. Thus, we can
say 1000 ≡ 4 (mod 12) for the reasonds discussed above. At the same time, 1000 ≡ 16 (mod 12). Similarly, the
statements 16 ≡ 1 (mod 3), 79 ≡ 1 (mod 11), and 4007 ≡ 17 (mod 19) are all valid.
The idea of residue classes is strange at first, but it is important to realize that we are not saying that two
integers are equal here. Rather, when we write a ≡ b (mod n), we are suggesting that a and b belong to the same
group of remainders and as such we can jump from one integer to the other freely.
4 Basic Arithmetic
Many of the rules of arithmetic apply to modular arithmetic as well. In particular, if a ≡ b (mod n) and c ≡ d
(mod n), then a + c ≡ b + d (mod n) and ac ≡ bd (mod n). This is most easily seen with a few examples.
Example 2. What are the remainders when 3333 + 4444 and 3333 · 4444 are divided by 5?
Solution. We have 3333 ≡ 3 (mod 5) and 4444 ≡ 4 (mod 5), so 3333 + 4444 ≡ 3 + 4 ≡ 7 ≡ 2 (mod 5). Similarly,
3333 · 4444 ≡ 3 · 4 ≡ 12 ≡ 2 (mod 5).
In general, we can take any integer and replace it with an integer within the same residue class. We can do this
multiple times within a problem.
2015
| · 2015
{z· . . . · 2015} .
2015 terms
Since 2015 ≡ 1 (mod 2014), when evaluating the remainder when dividing by 2014 we can replace each of these
2015’s with a 1. Therefore the desired answer is 1 · 1 · . . . · 1 = 1 .
Note that this solution can be shortened by replacing the 2015 with a 1 in the beginning of the problem, as
follows:
20152015 ≡ 12015 ≡ 1 (mod 2014).
The above problem is our first glimpse into the power of modular arithmetic. No human being could ever dream
of multiplying out 20152015 - it’s simply too computationally infeasible. Modular arithmetic helped us determine
the remainder when 20152015 is divided by 2014 without going through all the gory arithmetic!
Try your hand at the next problem before moving on.
Problem 1. Is 21100 − 12100 a multiple of 11?
Randolph High School Math League 2014-2015 Page 3
17198 = 4254871345860260773820291271704849130393265438068192609194205906081766431755337385
3755499288972428647279052646422715030862464546452440645808440896351754510501532667
43295026488304431966804630624591243393794658069711060298952254618629018195360609,
which does end in the two digits 09. Hooray for math!
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 8 (AMC 10B 2010). A palindrome between 1000 and 10, 000 is chosen at random. What is the probability
that it is divisible by 7?
Solution. Let XY Y X be a four-digit palindrome. Note that when expanded the integer can be rewritten as
1001X + 110Y . Note that 1001 is divisible by 7 and 110 ≡ 5 (mod 7), so
Therefore as long as Y is either 0 or 7, the resulting palindrome will be divisible by 7. There are 2 · 9 = 18 such
18
palindromes (since X 6= 0) and 10 · 9 = 90 total palindromes, so the requested probability is 90 = 15 .
7 Problems
1. [Paraguay 2012] Define a list of numbers with the following properties:
3. 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?
(A) 9 (B) 10 (C) 11 (D) 12 (E) 13
(This problem is here to help you figure out how to divide in modular arithmetic. It’s not as simple as the
other arithmetic operations are. As a hint, try to find a number that satisfies the given properties, and then
figure out how to find the desired remainder without guess-and-check.)
3 Yes, this actually appeared on a national olympiad. Do not ask me why.
Randolph High School Math League 2014-2015 Page 5
4. Using a similar method as we did in Example 7, prove the divisibility rule for 11: if N = a0 a1 a2 . . . an is a
positive integer, then N is divisible by 11 if and only if
a0 − a1 + a2 − · · · + an (−1)n
(Warning: at this point in the problem set, there’s a huge spike in difficulty. Sorry! Modular arithmetic
problems at this level are really really hard to find.)
5. Prove that
1 · 3 · 5 · . . . · 2013 + 2 · 4 · 6 · . . . · 2014
is divisible by 2015.
6. [Purple Comet HS 2013] There is a pile of eggs. Joan counted the eggs, but her count was off by 1 in the 1’s
place. Tom counted in the eggs, but his count was off by 1 in the 10’s place. Raoul counted the eggs, but his
count was off by 1 in the 100’s place. Sasha, Jose, Peter, and Morris all counted the eggs and got the correct
count. When these seven people added their counts together, the sum was 3162. How many eggs were in the
pile?
7. [Math League HS 1990-1991] The quadratic equation ax2 +bx+c = 0 has integral coefficients, and the value of
its discriminant is D. What is the smallest value of D > 48 for which the solutions of this quadratic equation
will be irrational?4
(A) 49 (B) 50 (C) 51 (D) 52 (E) 53
F 8. [Mandelbrot 2008-2009] Determine the smallest positive integer m such that m2 + 7m + 89 is a multiple of 77.
F 9. [Mandelbrot 2003-2004] How many zeroes occur at the end of the number 19996 + 6 · 1999 + 5?
(A) 4 (B) 5 (C) 6 (D) 7 (E) 8
F 10. [AMC 12B 2010] Arithmetic sequences (an ) and (bn ) have integer terms with a1 = b1 = 1 < a2 ≤ b2 and
an bn = 2010 for some n. What is the largest possible value of n?
(A) 2 (B) 3 (C) 8 (D) 288 (E) 2009
4 Hint: it may help to examine the possible remainders when a perfect square is divided by 4.
Randolph High School Math League 2014-2015 Page 6
2. How many positive integers n ≤ 120 satisfy both n 6= 3 (mod 4) and n 6= 4 (mod 3)?
3. Suppose p and q are two positive primes such that p − q = 2 and φ(pq) = 120. Find p + q.
4. Show that 2147 − 1 is divisible by 343.
n n
5. For all positive integers n, show that 42 + 22 + 1 is divisible by 7.
6. Prove that every rational number has a decimal representation that either terminates or repeats after finitely
many digits. (Yes, this is something you were taught in middle school, but you never got the chance to
actually see why it was true. Now’s your chance.)
7. [USAMO 1991] Show that, for any fixed integer n ≥ 1, the sequence
2 22
2, 22 , 22 , 22 , . . . (mod n)
is eventually constant.
8. [Unknown] Let n be a positive integer with n ≥ 3. Show that
nn n
nn − nn
is divisible by 1989.
9. [AoPS] Consider a number line consisting of all positive integers greater than 7. A hole punch traverses the
number line,
starting from 7 and working its way up. It checks each positive integer n and punches it if and
only if n7 is divisible by 12. (Here nk = (n−k)!k!
n!
.) As the hole punch checks more and more numbers, the
fraction of checked numbers that are punched approaches a limiting number ρ. If ρ can be written in the form
m
n , where m and n are positive integers, find m + n.
2001
10. [Canada 2003] Determine the last three digits of 20032002 .