0% found this document useful (0 votes)
864 views

Modular Arithmetic Handout

The document discusses modular arithmetic and two important theorems: the Chinese Remainder Theorem and Euler's Totient Theorem. It provides examples and solutions demonstrating how to use these theorems to solve problems involving modular exponentiation and congruences. Specifically, it shows how to reduce large exponential expressions like 2015p modulo a prime p using Fermat's Little Theorem, which follows as a corollary from Euler's Totient Theorem.

Uploaded by

Aryan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
864 views

Modular Arithmetic Handout

The document discusses modular arithmetic and two important theorems: the Chinese Remainder Theorem and Euler's Totient Theorem. It provides examples and solutions demonstrating how to use these theorems to solve problems involving modular exponentiation and congruences. Specifically, it shows how to reduce large exponential expressions like 2015p modulo a prime p using Fermat's Little Theorem, which follows as a corollary from Euler's Totient Theorem.

Uploaded by

Aryan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Modular Arithmetic

Adithya B., Brian L., William W., Daniel X.


9/2

§1 Chinese Remainder Theorem


Oftentimes, we need to handle congruences modulo composite numbers, e.g. modulo 6,
or modulo 210, etc. The Chinese Remainder Theorem is a useful tool that allows us to
transfer from multiple congruences to a single congruence:

Theorem 1.1 (Chinese Remainder Theorem)


Let a1 , a2 , . . . , an be pairwise coprime positive integers (that is, no two of these
numbers share a common factor greater than one), and b1 , b2 , . . . , bn be any integers.
Then the system of n congruences

x ≡ b1 (mod a1 ),
x ≡ b2 (mod a2 ),
··· ,
x ≡ bn (mod an )

is equivalent to the congruence x ≡ k (mod a1 a2 · · · an ) for some integer k. That is,


x satisfies all n congruences above if and only if x ≡ k (mod a1 a2 · · · an ).

Note that this is an existence theorem: it does not tell us how to find k. For example,
the theorem tells us that

x ≡ 1 (mod 2), x ≡ 2 (mod 3), x ≡ 3 (mod 5),

is equivalent to x ≡ k (mod 30) for some integer k, but it does not tell us what k is. (We
can manually find that k = 23.)

The Chinese Remainder Theorem is especially powerful because it allows us to collate


multiple congruences into a single congruence without having to actually solve the system
of congruences. This will be essential for the problems below.

Example 1.2 (2012 AIME II #12)


For a positive integer p, define the positive integer n to be p-safe if n differs in
absolute value by more than 2 from all multiples of p. For example, the set of 10-safe
numbers is {3, 4, 5, 6, 7, 13, 14, 15, 16, 17, 23, . . .}. Find the number of positive integers
less than or equal to 10, 000 which are simultaneously 7-safe, 11-safe, and 13-safe.

1
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

Solution. The p-safe condition translates nicely into modular arithmetic. In order for n
to be 7-safe, it has to be more than two away from any multiple of 7. This means it has
to be congruent to 3 or 4 modulo 7. Conversely, if n is congruent to 3 or 4 modulo 7
then it is more than 2 away from the nearest multiple of 7.

Similarly, n is 11-safe if and only if it is congruent to 3, 4, 5, 6, 7, or 8 modulo 11, and


n is 13-safe if and only if it is congruent to 3, 4, 5, 6, 7, 8, 9, or 10 modulo 13. For n to
be simultaneously 7-safe, 11-safe, and 13-safe, all of the following congruences must be
satisfied:

• n ≡ 3, 4 (mod 7),

• n ≡ 3, 4, 5, 6, 7, 8 (mod 11),

• n ≡ 3, 4, 5, 6, 7, 8, 9, 10 (mod 13).

Moreover, 7, 11, and 13 are pairwise relatively prime (they are all prime), so we can use
the Chinese Remainder Theorem to splice together these conditions. For example, the
congruences

• n ≡ 4 (mod 7),

• n ≡ 8 (mod 11),

• n ≡ 3 (mod 13).

have a unique solution modulo 7 · 11 · 13 = 1001. To find all possible solutions modulo
1001, we need to pick a residue modulo 7, a residue modulo 11, and a residue modulo 13;
each such choice results in exactly one residue modulo 1001. With our list above, we find
that this can be done in 2 · 6 · 8 = 96 ways. So there are 96 residues modulo 1001 that
are 7-safe, 11-safe, and 13-safe.

We now want to find the number of positive integers at most 10, 000 that work. From
our work above, we see that:

• There are 96 working integers in {1, 2, . . . , 1001},

• There are 96 working integers in {1002, 1003, . . . , 2002},

• ...,

• There are 96 working integers in {9010, 9011, . . . , 10010}.

So there are 960 working integers from 1 to 10010, inclusive. We just need to examine
the integers 10001, . . . , 10010 and subtract any overcounts to find the final answer.

Note that 10010 is a multiple of 7, 11, and 13. The next smallest multiples of 7, 11,
and 13 are 10003, 9999, and 9997, respectively. From this, we see that the only working
integers from 10001 to 10010 are 10006 and 10007. So we have two overcounts, and the
number of positive integers less than or equal to 10, 000 which are 7-safe, 11-safe, and
13-safe is 960 − 2 = 958 .

2
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

Example 1.3 (2011 AIME II #14)


There are N permutations (a1 , a2 , . . . , a30 ) of 1, 2, . . . , 30 such that for m ∈ {2, 3, 5},
m divides an+m − an for all integers n with 1 ≤ n < n + m ≤ 30. Find the remainder
when N is divided by 1000.

Solution. We’re given three different values of m to use; let’s investigate them separately.
For m = 2, the condition implies that

a1 ≡ a3 ≡ · · · ≡ a29 , a2 ≡ a4 ≡ · · · ≡ a30 (mod 2)

Since the ai need to be a permutation of (1, 2, . . . , 30), with 15 odd numbers and 15 even
numbers, this implies that a1 , a3 , . . . , a29 are all of the opposite parity as a2 , a4 , . . . , a30 .
Thus we can choose that either a1 , a3 , . . . , a29 are all even, or a1 , a3 , . . . , a29 are all odd.
There are 2 ways to do this.

Let’s take a look modulo 3. The condition gives us

a1 ≡ a4 ≡ · · · ≡ a28 , a2 ≡ a5 ≡ · · · ≡ a29 , a3 ≡ a6 ≡ · · · ≡ a30 (mod 3).

Again, since the ai are a permutation of (1, 2, . . . , 30), 10 of them congruent are to each
of 0, 1, and 2 modulo 3. So we can choose what a1 , a4 , . . . , a28 are modulo 3, then pick a
different residue for a2 , a5 , . . . , a29 , and use the last residue for a3 , a6 , . . . , a30 . We have
3! = 6 ways to do this.

Finally, for m = 5 we can use the same logic. We get

a1 ≡ a6 ≡ · · · ≡ a26 , a2 ≡ a7 ≡ · · · ≡ a27 , . . . , a5 ≡ a10 ≡ · · · ≡ a30 (mod 5).

We can choose the residues of a1 , a6 , . . . , a26 modulo 5, then pick a different residue for
a2 , a7 , . . . , a27 , and so on up to a5 , a10 , . . . , a30 . There ae 5! = 120 ways to assign residues
modulo 5.

We have now chosen a residue for each ai modulo 2, 3, and 5; by the Chinese Remainder
Theorem this results in a unique residue modulo 30, and hence a unique element of
{1, 2, . . . , 30}. So our choices uniquely define the sequence (a1 , a2 , . . . , a30 ). We’re not
done yet; we need to check if this sequence is a permutation. That is, we need to check
that no two elements are equal.

What happens if ai = aj ? This means that ai ≡ aj (mod 2), so that i ≡ j (mod 2).
We see this because

a1 ≡ a3 ≡ · · · ≡ a29 6≡ a2 ≡ a4 ≡ · · · ≡ a30 (mod 2).

Similarly, ai ≡ aj (mod 3), so i ≡ j (mod 3), and since ai ≡ aj (mod 5) we have i ≡ j


(mod 5). By the Chinese Remainder Theorem, we have i ≡ j (mod 30). But i and j
are between 1 and 30, so this forces i = j. Hence we conclude that our sequence is a
permutation; no two terms are equal. We had 2! ways to set the residues modulo 2, 3!
ways to set the residues modulo 3, and 5! ways to set the residues modulo 5, so the total
number of ways is
2! · 3! · 5! = 2 · 6 · 120 = 1440
and the answer is 440 .

3
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

§2 Euler’s Totient Theorem


Euler’s Totient Theorem is probably the most important theorem for dealing with
exponents in modular arithmetic. Using it, one can compute the residue of large powers
of numbers modulo a fixed n without having to resort to techniques such as “looking for
patterns.” To understand it, first we must know what the totient function is.

Definition 2.1. The totient of n, denoted φ(n), is the number of positive integers less
than or equal to n which are relatively prime to it.

We won’t go over it’s proof in this class, but the totient is easily computable via the
closed form     
1 1 1
φ(n) = n 1 − 1− ··· 1 −
p1 p2 pk
where p1 , p2 , . . . , pk are the primes dividing n, listed without repetition. The proof can
be done using Chinese Remainder Theorem on mods p1 , . . . , pk and is left as an exercise
to the reader.

Theorem 2.2 (Euler’s Totient Theorem)


Given an integer n > 1 and a natural a relatively prime to n, we have aφ(n) ≡ 1
(mod n)

Proof. Denote S the set of residues modn which are coprime with n. By definition,
|S| = φ(n). Now, consider the set T = {as (mod n)|s ∈ S}, which is the set of the
residues multiplied by a. As a is coprime with n, all elements of T are coprime with n as
well. Furthermore, no two elements in T are the same, since as ≡ as0 (mod n) =⇒ s ≡ s0
(mod n). So, T is a set of numbers coprime to n with magnitude |T | = |S| = φ(n). Hence,
T = S.

Of course, as they are the same set, the product of all the elements should be the
same too. Hence,
Y Y Y Y Y
s≡ t (mod n) =⇒ s≡ as ≡ aφ(n) s (mod n)
s∈S t∈T s∈S s∈S s∈S

=⇒ aφ(n) ≡ 1 (mod n)
as desired.

Corollary 2.3
Fermat’s Little Theorem For any prime p and a coprime to p, we have ap−1 ≡ 1
(mod p)

Proof. This is just Euler’s Totient Theorem at n = p.

4
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

Example 2.4 (NIMO)


Let p = 2017 be a prime. Find the remainder when
 p  p  p
2015p
 
1 2 3
+ + + ··· +
p p p p

is divided by p.

Solution. First, let’s try to get rid of the floors. From FLT, we note ap ≡ a (mod p), so
 p
a ap − a
= .
p p
Therefore, it suffices to determine
p−2 p
X a −a
(mod p)
p
a=1

which is equivalent to finding p−2 p 2


P
a=1 (a − a) (mod p ). It isn’t immediately apparent how
to find this. Euler’s theorem would only be helpful if the exponent was close to p(p − 1).
Therefore, we instead try another trick. Let’s try to pair up terms in the sum by adding
the terms for a and p − a. Note that
   
p p p p p p−1 p
a + (p − a) = a + p − p a + ··· + pap−1 − ap ≡ 0 (mod p2 )
p−1 1

since every remaining term in the sum is divisible by p2 (The last term in the expansion
of (p − a)p is negative because p is an odd prime). Now, we have

(ap − a) + ((p − a)p − p + a) ≡ 0 − p ≡ −p (mod p2 ).

Now, the first term in the sum p−2 p 2


P
a=1 (a − a) (mod p ) is 0, and the other p − 3 terms
can be paired up so that the total value is
p−2
X p−3 p(p − 3) p(p + 3)
(ap − a) ≡ · (−p) = − ≡ (mod p2 ).
2 2 2
a=1

Therefore, we have
p−2 p p(p+3)
X a −a 2 p+3
≡ ≡ (mod p).
p p 2
a=1

For p = 2017, the answer is 1010 .

Example 2.5 (Bulgaria 1996)


Find all pairs of primes p, q such that pq | (5p − 2p )(5q − 2q ).

Solution. WLOG, let’s assume p ≥ q. By Fermat’s Little Theorem,

5p − 2p ≡ 3 (mod p)

5q − 2q ≡ 3 (mod q)

5
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

Now, if q = 3, then we see that we can also have p = 3. If q = 3 and p > 3, then
p|(53 − 23 ) = 117. This implies p = 13. Therefore, with permutations, we obtain the
pairs (3, 3), (3, 13), (13, 3).
Now, let’s assume p ≥ q > 3. In this case, clearly gcd(q, 5q − 2q ) = 1, so 5p − 2p ≡ 0
(mod q). This implies 5p ≡ 2p (mod q). From FLT again, we know 5q−1 ≡ 2q−1 ≡ 1
(mod q). Now, since gcd(p, q − 1) = 1, there exist integers a, b such that
ap + b(q − 1) = gcd(p, q − 1) = 1.
Note that
5ap+b(q−1) = (5p )a · (5q−1 )b = (2p )a · (2q−1 )b = 2ap+b(q−1) (mod q).
However, this implies 5 ≡ 2 (mod q), which can only happen when q = 3, so we are done.
The only solutions are (3, 3), (3, 13), (13, 3) .

§3 Orders
From Fermat’s Little Theorem, we know that ap−1 ≡ 1 (mod p) for p - a. But, often
times we don’t need to raise a to that high of a power in order to get it to 1 (mod p).
For example, 26 ≡ 1 (mod 7), but 23 ≡ 1 as well.

This motivates us to define the order of a (mod p), which is the minimum e > 0
such that ae ≡ 1 (mod p), denoted e = ordp (a). Note that order exists, since it is at
most p − 1.

Theorem 3.1
If ak ≡ 1 (mod p) for prime p and p - a, then ordp (a)|k.

Proof. Denote e = ordp (a). By definition, ae ≡ 1 (mod p), so ane ≡ 1 (mod p) for any n
by raising both sides to the nth power. So, choose n such that ne ≤ k < (n + 1)e. This
way, by dividing the relations, we get ar ≡ 1 (mod p), where r = k − ne is the remainder
when k is divided by e.

However, 0 ≤ r < e, and e was defined to be the minimal positive power of a to


yield 1 (mod p). Hence, we must have r = 0 and e|k, as desired.

Corollary 3.2
ordp (a) divides p − 1

Proof. We know ap−1 ≡ 1 (mod p), and applying Theorem 3.1 gives the desired result.

As orders can be really small, a natural follow-up question might be whether or not FLT
is actually tight. In fact, there do exist numbers with order p − 1 for all primes p, and
such numbers are known as primitive roots.

Theorem 3.3 (Gauss)


Every prime admits a primitive root.

6
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

Proof. We first begin with Lagrange’s Theorem which is obviously true for the reals but
also holds mod p:

Theorem 3.4 (Lagrange)


A polynomial P (x) has at most deg P roots modulo p.

Proof. We prove this with induction on deg P . The result is clear when deg P = 1. Now,
suppose that we have the claim for polynomials of degree deg P − 1.

If P does not have any roots modulo p, then we are already done. Otherwise, sup-
pose it has root r. We can perform synthetic division on P to get P (x) ≡ (x − r)Q(x) + k
(mod p). However, since r is a root, k = 0. So, P (x) ≡ (x − r)Q(x) (mod p). Now, Q(x)
has degree 1 less than P , so it has at most deg P − 1 roots. Hence, P has at most deg P
roots.
Now, note that if k|p − 1 for some k, then we can write
xp−1 − 1 = (xk − 1)Q(x)
for some Q. xp−1 − 1 admits p − 1 roots by FLT, so the RHS should also have p − 1 roots.
However, xk − 1 has at most k roots and Q(x) has at most p − 1 − k, by Lagrange’s
Theorem. So, in order for equality to hold, xk − 1 actually has exactly k roots.

Now, we are ready to finish. Let N (e) denote the number of residues modulo p with
order e. By Theorem 3.1, we have that
X
k= N (e)
e|k

for any k|p − 1, since the residues which satisfy xk ≡ 1 are precisely those whose orders
divide k. However, we’ve seen this type of summation a long time ago, we can compute
N (e) explicitly with Mobius Inversion! In fact, we get that
X e
N (e) = iµ = φ(e)
i
i|e

(if you are unfamiliar with Mobius Inversion, you can also note that the function N (e) is
uniquely defined by the summation relation, and φ(e) works by Dirichlet Convolution, so
it has to be the correct function.)

As N (p − 1) denotes the number of primitive roots, we see that we actually have


φ(p − 1) primitive roots (mod p), as desired.

Remark 3.5. The existence of a primitive root actually allows us to “generate” all elements
of the residue class. To see this, let ζ be a primitive root modulo p. Since ζ k 6= 1 (mod p)
for any k < p − 1, this means that the sequence ζ, ζ 2 , . . . , ζ p−1 does not cycle, and hence
must cover every single nonzero residue.

In fact, if we can express a number a as ζ k (mod p), this gives us a very efficient way
to compute its order. We have that ae ≡ ζ ke , and the order of ζ is known to be p − 1. Hence,

e p−1
a ≡ 1 (mod p) ⇐⇒ p − 1|ke ⇐⇒ e
gcd(k, p − 1)

7
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

p−1
Hence, the order of a is gcd(k,p−1) . Using ζ as a generator, see if you can rederive the fact
that N (e) = φ(e).

Example 3.6 (2019 AIME I #14)


Find the least odd prime factor of 20198 + 1.

Solution. If p | 20198 + 1, then 20198 ≡ −1 (mod p). Therefore, 201916 ≡ (−1)2 = 1


(mod p). Since 20198 6≡ 1 (mod p) and 201916 ≡ 1 (mod p), we have that ordp (2019) =
16. Since ordp (2019) | p − 1, we have 16 | p − 1. This implies p ≡ 1 (mod 16). We can
now test primes to find the smallest odd prime that divides 20198 + 1. The first few
primes that are 1 mod 16 are 17 and 97. Note that

20198 ≡ (−4)8 ≡ 164 ≡ (−1)4 ≡ 1 (mod 17)

so 17 does not divide it. Also, note that

20198 ≡ (−18)8 ≡ 334 ≡ 222 = 484 ≡ −1 (mod 97).

Therefore, the smallest odd prime factor is 097 .

Example 3.7 (HMMT 2016)


For positive integers n, let cn be the smallest positive integer for which ncn − 1 is
divisible by 210, if such a positive integer exists, and cn = 0 otherwise. What is
c1 + c2 + · · · + c210 ?

Solution. Note that cn is basically just the “order” of cn mod 210.. Unfortunately, many
of the theorems we have proven above only apply to primes. So, in order to compute cn ,
we instead consider the orders of n mods 2, 3, 5, 7. If we denote them as wn , xn , yn , zn
respectively, then we have that cn = lcm(wn , xn , yn , zn ).

However, we already have a good idea about the distributions of wn , xn , yn , zn by our


proof of Theorem 3.3. This is because we know exactly φ(k) of the p − 1 residues mod p
have order k, where k|p − 1.

Let’s see how this applies to zn , for example. 7 has 6 nonzero residues, and by the above
we know 2 of them have order 6, 2 have order 3, 1 has order 2 and 1 has order 1. So, the
orders (1, 2, 3, 6) occur in ratio 1 : 1 : 2 : 2.

Similarly, yn = (1, 2, 4) occurs in ratio 1 : 1 : 2, xn = (1, 2) occurs in ratio 1 : 1,


and wn is always 1.

Now, note that the lcm of all possible values of wn , xn , yn , zn is 12, so c|12. Now,
it suffices to find out how often each divisor of 12 occurs.

The only way 4|cn is if yn = 4, which has probability 12 , and the only way it is not
divisible by 2 is if zn = 1, 3, and everything else is 1, which happens with probability
1 1 1 1 1 7
2 · 4 · 2 = 16 . Hence, cn has a 16 chance of being odd, 16 chance of being divisible by 2
but not 4, and a 12 chance of being divisible by 4.

8
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

On the other hand, factors of 3 only come from zn . It’s easy to see that it has probability
2
3 of being divisible by 3. Now, as the powers of 2, 3 in cn are independent, we can get
the expected value of cn just by multiplying the expected value of its powers of 2,3. In
particular:   
1 2·7 4 1 2·3 329
E(cn ) = + + + =
16 16 2 3 3 48
329
There are φ(210) = 48 nonzero values of cn , so our answer is 48 · 48 = 329 .

Example 3.8 (HMMT 2014)


Determine the sum of all positive integers m such that 1 ≤ m ≤ 50 and there exists
an integer n for which m divides nn+1 + 1.

Solution. To start, we see that all odd m work. Set n = m−1 so that nn+1 ≡ (−1)m ≡ −1
(mod m), as desired.
Now, we will find which even m work. Clearly, n must be odd in this case. When
n = 2k + 1,

nn+1 + 1 ≡ (2k + 1)2k+2 + 1 = ((2k + 1)k+1 )2 + 1 ≡ 2 (mod 4).

Now, since nn+1 + 1 is the sum of two perfect squares, all odd prime factors must be
1 mod 4. Therefore, all odd prime factors of m are 1 mod 4. Since m is even and m ≤ 50,
all prime factors are less than 25. The possible prime factors are 5, 13, 17. Therefore, the
only possible even m that could work are m = 2, 10, 26, 34, 50. We can find a construction
in each of these cases. Note that if n2 ≡ −1 (mod m 2 ) and n ≡ 1 (mod 4), then n + 1 ≡ 2
(mod 4), so
m
nn+1 ≡ (−1)odd ≡ −1 (mod ).
2
Also nn+1 + 1 ≡ 1 (mod 2), so we can conclude m divides nn+1 + 1 by the Chinese
Remainder Theorem. The existence of such an n is because all odd prime factors of m
are 1 mod 4 (We will discuss more about this in next week’s handout!). From this, we
can complete our constructions:

• For m = 2, let n = 1.

• For m = 10, let n ≡ 1 (mod 4) and n ≡ 2 (mod 5)

• For n = 26, let n ≡ 1 (mod 4) and n ≡ 5 (mod 13)

• For n = 34, let n ≡ 1 (mod 4) and n ≡ 4 (mod 17)

• for n = 50, let n ≡ 1 (mod 4) and n ≡ 7 (mod 25)

Therefore, our final answer is

(1 + 3 + 5 + · · · + 49) + (2 + 10 + 26 + 34 + 50) = 747 .

9
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

Example 3.9 (Online Math Open 2013)


Find the sum of all integers m with 1 ≤ m ≤ 300 such that for any integer n with
n ≥ 2, if 2013m divides nn − 1, then 2013m also divides n − 1.

Solution. Let M = 2013m. We want to find M such that nn ≡ 1 (mod M ) implies n ≡ 1


(mod M ). It is clear that gcd(n, M ) = 1. We begin by proving the following key lemma:

Lemma 3.10
For any prime p, we have p | M if and only if every prime factor of p − 1 divides M .

Proof. We will first show that this condition is necessary. Suppose otherwise, that we
have primes p, q such that p|M , q|p − 1, q - M . Let k be the largest positive integer such
pk−1 p−1
that pk |M . Consider an arbitrary primitive root g mod pk . Let a ≡ g q (mod pk )
so that aq ≡ 1 (mod pk ) and a 6≡ 1 (mod p). Now, we let n be a value such that n ≡ 1
(mod M pk
), n ≡ a (mod pk ), and n ≡ 0 (mod q). Because these modulos are relatively
prime, such an n exists by the Chinese Remainder Theorem. Now, we note that n satisfies
M |nn − 1 and M - n − 1, a contradiction.
Now, we can easily show that this condition is sufficient. Suppose that nn ≡ 1 (mod M ).
We will show n ≡ 1 (mod M ). It suffices to show this for every prime power dividing M .
Consider a prime p dividing M , and let pk be the largest power dividing M . Since, nn ≡ 1
(mod M ), we have gcd(n, M ) = 0, which implies gcd(n, pk−1 (p − 1)) = 1 because every
prime factor of p − 1 divides M . Since nn ≡ 1 (mod pk ), we see ordpk n | n. However,
we also have ordpk (n) | φ(pk ) = pk−1 (p − 1). Therefore, because n and pk−1 (p − 1) are
relatively prime, we can conclude that ordpk (n) = 1, as desired. Thus, our lemma is
proven.

Now, since 3 divides M = 2013m, we must have 2 | M . Also, since 11 divides 2013m,
we must have 5 | m. Therefore, 10 | m. Let m = 10k so that

M = 20130k = 2 · 3 · 5 · 11 · 61 · k.

From the given range, k can go from 1 to 30. We can check the condition in the lemma
for all of the prime from 1 to 30 first (If p1 , p2 , . . ., pi , satisfy the condition separately,
then p1 · p2 · · · pi clearly satisfies it too). We see that the only prime number that does
not satisfy the condition is 29. Therefore, every value of k from 1 to 30 works, except 29.
Our final answer is
10(1 + 2 + 3 + · · · + 28 + 30) = 4360 .

Example 3.11 (China 2009)


Find all pairs of primes p, q such that pq | 5p + 5q .

Solution. First’s, let’s consider the case p = q. Then, we have p2 | 2 · 5p . Since 2 · 5p only
has the prime divisors 2, 5 and is not a multiple of 4, we must have p = q = 5.
We now consider p 6= q. Let’s consider if either of p, q is 5. WLOG, let q = 5. Then, we
have 5p | 5p + 55 . We need 5p + 55 ≡ 0 (mod p), but by FLT, 5p + 55 ≡ 5 + 55 (mod p).

10
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

This implies p | 5 + 55 = 3130 = 2 · 5 · 313, so p = 2, 313. Accounting for permutations,


the pairs in this case are (2, 5), (313, 5), (5, 2), (5, 313).
Now, we have the case of neither p, q is equal to 5. By FLT, we have 5p + 5q ≡ 5 + 5q ≡
5(1 + 5q−1 ) ≡ 0 (mod p). Therefore, p | 1 + 5q−1 , so

5q−1 ≡ −1 (mod p) =⇒ 52q−2 ≡ 1 (mod p).

If p 6= 2, we have ordp (5) | 2(q − 1) and ordp (5) - q − 1 (In the case p = 2, we see 5q−1 ≡ 1
(mod p) as well). Define ν2 (n) to be the largest positive integer k such that 2k | n. We
must have ν2 (ordp (5)) = 1+ν2 (q −1). However, from FLT, we know ordp (5) | φ(p) = p−1.
Therefore,
1 + ν2 (q − 1) = ν2 (ordp (5)) ≤ ν2 (p − 1).
We similarly have

5p−1 ≡ −1 (mod q) =⇒ 52p−2 ≡ 1 (mod q).

From this, assuming q = 6 2, we can similarly obtain 1 + ν2 (p − 1) ≤ ν2 (q − 1). Adding


this inequality with the inequality above is a direct contradiction. Therefore, one of p, q
must be equal to 2. WLOG, let q = 2. Then, we have 2p | 5p + 52 , and clearly 2 | 5p + 52 ,
so we just need p | 5p + 52 . We have 5p + 52 ≡ 5 + 52 (mod p), so p | 30. Thus, we
need p = 3, as we have already accounted for the cases p = 5 and p = q. Accounting for
permutations, we have the solutions (2, 3), (3, 2).
To conclude, all of the solutions are (5, 5), (2, 5), (5, 2), (5, 313), (313, 5), (2, 3), (3, 2) .

11
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

§4 Problems
Problem 4.1 (2020 HMMT Combinatorics #2). How many positive integers at most
420 leave different remainders when divided by each of 5, 6, and 7?
Problem 4.2 (2017 AMC 12 #21). Last year Isabella took 7 math tests and received
7 different scores, each an integer between 91 and 100, inclusive. After each test she
noticed that the average of her test scores was an integer. Her score on the seventh test
was 95. What was her score on the sixth test?
Problem 4.3 (Fermat Christmas Theorem). Let p ≡ 3 (mod 4) be a prime, and let a
and b be positive integers such that p divides a2 + b2 . Show that p | a and p | b.
Problem 4.4 (Wilson). Prove that (p − 1)! ≡ −1 (mod p).
Problem 4.5. Prove that if p ≡ 1 (mod 4), then there is an element x ∈ Z/pZ such
that x2 ≡ −1 (mod p).
Problem 4.6 (2013 AIME I #11). Ms. Math’s kindergarten class has 16 registered
students. The classroom has a very large number, N , of play blocks which satisfies the
conditions:
(a) If 16, 15, or 14 students are present, then in each case all the blocks can be
distributed in equal numbers to each student, and
(b) There are three integers 0 < x < y < z < 14 such that when x, y, or z students
are present and the blocks are distributed in equal numbers to each student, there are
exactly three blocks left over.
Find the sum of the distinct prime divisors of the least possible value of N satisfying
the above conditions.
Problem 4.7 (2018 AIME I #11). Find the least positive integer n such that when 3n
is written in base 143, its two right-most digits in base 143 are 01.
Problem 4.8 (2001 AIME I #10). How many positive integer multiples of 1001 can be
expressed in the form 10j − 10i , where i and j are integers and 0 ≤ i < j ≤ 99?
Problem 4.9 (2011 AIME I #11). Let R be the set of all possible remainders when a
number of the form 2n , n a nonnegative integer, is divided by 1000. Let S be the sum of
all elements in R. Find the remainder when S is divided by 1000.
Problem 4.10. Find all integers n ≥ 1 such that n divides 2n − 1.
Problem 4.11. Let p be a prime and n a positive integer. Determine the remainder
when 1n + 2n + · · · + (p − 1)n is divided by p, as a function of n,and p.
Problem 4.12. Find all integers n ≥ 1 such that n divides 2n−1 + 1.
nn n
Problem 4.13 (Balkan). Let n be a positive integer with n ≥ 3. Show that nn − nn
is divisible by 1989.
n
Problem 4.14 (Euler). Prove that all factors of 22 + 1 are of the form k · 2n+1 + 1.
Problem 4.15 (2000 IMO Shorlist N1). Determine all positive integers n ≥ 2 that
satisfy the following condition: for a and b relatively prime to n we have a ≡ b (mod n)
if and only if ab ≡ 1 (mod n).
Problem 4.16 (2006 China TST). Find all positive integers a and n for which n divides
(a + 1)n − an .

12
Adithya B., Brian L., William W., Daniel X. (9/2) Modular Arithmetic

Problem 4.17 (2005 IMO Shorlist N6). Let a, b be positive integers such that bn + n is
a multiple of an + n for all positive integers n. Prove that a = b.

Problem 4.18 (USA TST 2003/3). Find all ordered prime triples (p, q, r) such that
p | q r + 1, q | rp + 1, and r | pq + 1.

13

You might also like