0% found this document useful (0 votes)
9 views32 pages

Modular Arithmetic Basics: 2.1 Motivation

Chapter 2 introduces the basics of modular arithmetic, explaining the concept of equivalence in terms of remainders and how it relates to divisibility. It covers properties of modular arithmetic, including addition and multiplication, and introduces residue classes. The chapter also discusses the periodic nature of sets formed by multiples of integers under modulo operations and establishes the uniqueness of these sets when the integer and the modulus are coprime.

Uploaded by

deepatewari81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views32 pages

Modular Arithmetic Basics: 2.1 Motivation

Chapter 2 introduces the basics of modular arithmetic, explaining the concept of equivalence in terms of remainders and how it relates to divisibility. It covers properties of modular arithmetic, including addition and multiplication, and introduces residue classes. The chapter also discusses the periodic nature of sets formed by multiples of integers under modulo operations and establishes the uniqueness of these sets when the integer and the modulus are coprime.

Uploaded by

deepatewari81
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

Chapter 2

Modular Arithmetic Basics

2.1 Motivation
In divisibility, we saw that dealing with remainders was at times more useful, for instance
if r = 0 we have divisibility. The main reason for this is that remainders are smaller than
the original numbers. This was the idea on which Euclid’s Algorithm was based. Modular
arithmetic dwells on this idea in much more depth. We start off by a different motivation,
and we would later see the remainder idea is the same.
Consider the following clock face

The clock has only the numbers from 1 to 12. Where to place the other numbers? If we
think about it, we would place 13 over 1. So then 13 ≡ 1 on a clock. (we don’t write 13 = 1
since that’s not true, but ≡ means ”equivalent to”, which fits here).
Also, 26 ≡ 2 and 100 ≡ 4. We would in general write a ≡ b if a, b are the same points on
the clock.

Question 2.1.1. Give a mathematical characterization/formula of when two points are the
same on the clock.

If you said 12 | a − b, then congrats, you got it right. So a ≡ b on the clock when
12 | a − b. But there are more things than a clock in this world. How would the general
” ≡ ” be defined?

45
2. Modular Arithmetic Basics

In general, for any integer n we would write

a ≡ b (mod n)

if n | a − b.

Question 2.1.2. Is 131 ≡ 32 (mod 11)?

Question 2.1.3. Why is 131 ≡ −1 (mod 11)?

So, negative numbers are also allowed.

Problems for Practice


Problem 2.1.1. Show that a + n ≡ a (mod n).

Problem 2.1.2. Let a, n be fixed integers. Show that the set of integers b such that b ≡ a
(mod n) form an arithmetic progression. What is the common difference?

Problem 2.1.3. Show that the set of integers a such that a ≡ 0 (mod n) is the set of
multiples of a.

2.2 Remainder Idea


The set of integers a such that a ≡ 2 (mod 5) is infinite, which is S2 = {. . . , −8, −3, 2, 7, 12, 17, . . . }.
The set of integers a such that a ≡ 9 (mod 5) is infinite, which is S4 = {. . . , −6, −1, 4, 9, 14, 19, . . . }.
Infinite sets can be harder to deal with. So instead, we only consider the smallest non-
negative element here.

Question 2.2.1. In the set of integers a such that a ≡ b (mod n) for some fixed n, convince
yourself that the smallest non-negative element is the remainder when b is divided by n.

For example, for a ≡ 9 (mod 5), the smallest element is 4, which is the remainder when
9 is divided by 5.
In general, when we write a ≡ r (mod n), we try and keep the second number as the
remainder for simplicity. Thus,

12 ≡ 2 (mod 10)
120 ≡ 0 (mod 15)
11 ≡ 11 (mod 21)

So in a ≡ r (mod n), if r is the remainder, we would have 0 ≤ r < n (why?).

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 46
2. Modular Arithmetic Basics

2.3 Residue classes


Suppose n = 3. There are only 3 possible remainders on division by 3 : 0, 1 and 2. So we can
put every integer in one column of the following table:

0 (mod 3) 1 (mod 3) 2 (mod 3)


.. .. ..
. . .
−6 −5 −4
−3 −2 −1
0 1 2
3 4 5
6 7 8
.. .. ..
. . .
In Divisibility, we studied the multiplication table which was the first column. So, modular
arithmetic gives us a better grip over ALL integers. So in some sense, the whole chapter
that we did on divisibility is only the first column of our table!
The three columns above are called the 3 ”residue classes” modulo 3. In general we have
the following:
Definition 2.3.1. Pick a natural number n, and a non-negative number r < n. Then the
rth residue class is the set of integers a that satisfy a ≡ r (mod n). Equivalently, it is the
set of all integers that leave r as a remainder when divided by n.
These integers are:

{. . . , r − 2n, r − n, r, r + n, r + 2n, r + 3n, . . . }.

Problems for Practice


Problem 2.3.1. Guess why the above classes are called ”residue” classes.

Problem 2.3.2. Show that the number of the classes modulo n is exactly n.

2.4 Basic Properties


As in divisibility, does modular arithmetic respect addition? That is, is the following true?

a≡r (mod n), b ≡ s (mod n) =⇒ a + b ≡ r + s (mod n)?

Question 2.4.1. We have 10 ≡ 1 (mod 3) and 8 ≡ 2 (mod 3). What is 10 + 8 (mod 3)? Is
it 1 + 2?
The answer is yes! To see why, write a = nx + r and b = ny + s. Then

a + b = n(x + y) + (r + s).

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 47
2. Modular Arithmetic Basics

Ok, so do they preserve multiplication? That is,

a≡r (mod n), b ≡ s (mod n) =⇒ ab ≡ rs (mod n)?

Question 2.4.2. We have 10 ≡ 1 (mod 3) and 8 ≡ 2 (mod 3). What is 10 × 8 (mod 3)? Is
it 1 × 2?

Again, the answer is yes! I will leave it as an exercise to prove.


Thus, we have the following two very important properties:

Theorem 2.4.1 (Properties of Modulus). Let a, b, r, s be integers such that for a given
integer n, we have a ≡ r (mod n) and b ≡ s (mod n). Then

1. a + b ≡ r + s (mod n).

2. ab ≡ rs (mod n).

This is better than Theorem 1.3.1 to find the remainder since we can directly use the
second property here without having to completely multiply a = nx + r and b = ny + s.

2.4.1 Why congruence is more useful than equality


A small note on why this modular symbol is really helpful. As we have seen, showing equality
is hard in number theory, and there are more interesting relations between numbers than
being equal. The ≡ sign just behave likes the = sign, since we can add, subtract and multiply
anything on the two sides just as in equations (later we will see how to divide). We can
exponentiate stuff and practically anything we can do with = applies here.

a ≡ b (mod n) =⇒ a + c ≡ b + c, ac ≡ bc, ac ≡ bc (mod n).

Thus, how = helps us in linear equations and all, ≡ helps us in showing divisibility and
related stuff.

Problems for Practice


Problem 2.4.1. Show that ab has remainder rs mod n by writing a = nx + r and b = ny + s
and evaluating ab.

Problem 2.4.2. Find the remainder when 210 is divided by 10.

Problem 2.4.3. Find 1002 × 560 (mod 7).

Problem 2.4.4. Show that if a ≡ b (mod n), then ka ≡ kb (mod n) for any integer k.

We can now destroy some problems from the last chapter that were challenging back
then:

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 48
2. Modular Arithmetic Basics

Problem 2.4.5. Show that a − b | an − bn for any integer n.

Problem 2.4.6. If p is an odd prime, and a, b are coprime, show that


 p
a + bp

gcd , a + b ∈ {1, p}.
a+b

Some interesting results can be very easily derived using modular arithmetic:

Problem 2.4.7 (Very Important). Let f be a polynomial with integer coefficients. Show
that a − b | f (a) − f (b) for any integers a, b. This is the same as saying f (a + d) ≡ f (a)
(mod d).

Problem 2.4.8 (Important). Show that ka ≡ kb (mod n) implies a ≡ b (mod n) if and


only if gcd(k, n) = 1.

Let’s try a nice problem together:

Example 2.4.1 (Russia 2001)

Find all primes p and q such that p + q = (p − q)3 .

Firstly, test some values of (p, q) and guess the answer. After that let’s try to solve it
systematically.
Directly expanding the right side won’t be so useful. Let’s take the equation modulo
something special. The most obvious choices are mod p and mod q. We can try both. Mod p
gives q ≡ −q 3 (mod p) and so p | q(q 2 + 1). Mod q gives p ≡ p3 (mod q) and so q | p(p2 − 1).
Not very useful.
However, here’s the trick. As p + q = (p − q)3 , we also have (p + q) | (p − q)3 . So,
(p − q)3 ≡ 0 (mod p + q). But p − q ≡ −2q (mod p + q) so (−2q)3 ≡ 0 =⇒ (p + q) | 8q 3 .
Now what we note is that if gcd(p + q, q) 6= 1, then gcd(p, q) = gcd(p + q, q) 6= 1 implies
p = q. In that case, however, we get p + p = (p − p)3 = 0, which is impossible.
So gcd(p+q, q) = 1. Hence in p+q | 8q 3 , we must have p+q | 8 because the q 3 contributes
nothing. So p + q ∈ {1, 2, 4, 8}. We can now manually list positive numbers that add to 8,
which are (1, 7), (2, 6), (3, 5), (4, 4). As p, q are primes, the only possible pair is (p, q) = (3, 5)
or (5, 3). Is this the answer you guessed?

2.5 Two special Equal Sets


Consider any number a and a prime p so that gcd(a, p) = 1 (this is the same as saying a 6= 0
(mod p)). Let’s see what happens to the non-negative multiples of a :

S = {0, a, 2a, 3a, . . . } (mod p).

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 49
2. Modular Arithmetic Basics

It’s better if we work with an example. Suppose a = 3 and p = 7. Then

S = {0, a, 2a, . . . } = {0, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, . . . }.

If we consider the elements of the set modulo 7, then

S ≡ {0, 3, 6, 2, 5, 1, 4, 0, 3, 6, 2, 5, 1, 4, 0, 3, 6, . . . } (mod 7).

We observe the sequence is periodic.


Question 2.5.1. What’s the periodicity?
In general too, we observe that ia ≡ (i + p)a (mod p) and so we can write S =
{0, a, 2a, . . . , (p − 1)a} because elements don’t repeat in sets (we are talking about sets
here, not multisets). Can we shorten this set further? That is, are there any more equal
numbers in here?
Let’s take the help of our example once more. Suppose a = 3 and p = 7. Then

S = {0, a, 2a, . . . , 6a} = {0, 3, 6, 9, 12, 15, 18} = {0, 3, 6, 2, 5, 1, 4} (mod 7).

Aha! No elements are equal. Can we prove this in general?


Suppose two elements were equal. Then they would be of the form ai, aj for 0 ≤ i 6= j ≤
(p − 1). Then

ai ≡ aj (mod p) =⇒ a(i − j) (mod p) ≡ 0 =⇒ p | a(i − j).

But we assumed gcd(a, p) = 1 at the start! Hence, we get p | (i − j) (why?). Is this possible?
Question 2.5.2. Try and find two integers i 6= j between 0, p − 1 such that p | i − j.
If you tried to, you would realize this is not possible. And the reason is simple, as
0 ≤ i 6= j < p, hence 0 < |i − j| < p. Thus, this is impossible, and we are done!
Now note that {0, a, 2a, . . . , (p − 1)a} has p elements, and all these are distinct. However,
since there are only p remainders possible, hence this set must be the set of ALL remainders!
For instance, in our example we saw that

{0, a, 2a, . . . , 6a} = {0, 3, 6, 9, 12, 15, 18} = {0, 3, 6, 2, 5, 1, 4} (mod 7),

and observe that the last set contains all the remainders mod 7. Cool, isn’t it!

2.5.1 Interlude (Equal Sets)


What do equal sets mean? These are sets with the same elements. So what’s the difference
in them?
{1, 4, 6, 2} = {4, 6, 1, 2}.
That’s right, the only difference between them is the order of elements. In problem solving,
whenever we prove two sets are equal, the most common things we do is to equate the sum of

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 50
2. Modular Arithmetic Basics

elements, the sum of squares of elements and the product of element, because these operation
don’t depend on the order. Out of all these, sum of elements is the most useful, and is very
strong in its applications. It should be the first thing you do on seeing equal sets!

So, in our context, we basically derived that S = {0, 1, 2 . . . , (p − 1)} modulo p. Note
here that the element 0 in S is 0 × a and in {0, 1, . . . , (p − 1)} is the first element. So we can
delete 0 from both the sets. Then we obtain:

Theorem 2.5.1 (Two Equal Sets). Let p be a prime and consider S = {1, 2, . . . , p − 1} to
be the set of non-zero remainder modulo p. Let a be any integer coprime to p.. Then

aS ≡ S (mod p).

Here, aS means the set obtained on multiplying each element of S by a. This gives us
many interesting results.

2.6 Fermat’s Little Theorem


Now let’s see where can we use this theorem. Firstly, let’s multiply the elements of both the
sets and equate them:

a · 2a · 3a · · · (p − 1)a ≡ 1 · 2 · 3 · · · (p − 1) (mod p).

This gives
ap−1 · (p − 1)! ≡ (p − 1)! (mod p).
Now, gcd((p − 1)!, p) = 1, hence we can divide both the sides by (p − 1)! by Problem 2.4.8.
Hence ap−1 ≡ 1
Now comes the interesting part: Since a was any number coprime to p, hence we obtain
the famous Fermat’s Little Theorem:

Theorem 2.6.1 (Fermat’s Little Theorem). Let a be any number relatively prime to a prime
p. Then
ap−1 ≡ 1 (mod p).

This is a very powerful result. It helps us compute an for large n. Don’t forget the
”relatively prime” part of the theorem.
In fact, we also have the following:

Theorem 2.6.2 (Fermat’s Little Theorem). Let a be any number. Then

ap ≡ a (mod p).

You can say we just multiplied both sides by a, so what’s special. The reason is that you
don’t need a, p relatively prime here!

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 51
2. Modular Arithmetic Basics

Problems for Practice


Problem 2.6.1. Show that ap ≡ a (mod p) holds in the case when gcd(a, p) 6= 1.

Problem 2.6.2. Let a, b be integers and p a prime. Show that p divides abp − ap b.

Problem 2.6.3. Find


250 (mod 7).

2.7 Inverses
Now let’s look at the definition of ”equal sets”. It means that for any integer 0 < b < p, we
can find an integer x such that
ax ≡ b (mod p).
In particular, if b = 1, then ax ≡ 1 (mod p).
What this means is if gcd(a, p) = 1, then there always exists a multiple of a which is 1
mod p.

Theorem 2.7.1 (Inverses). Let p be a prime and a be an integer coprime to p. Then there
always exists an integer x such that

ax ≡ 1 (mod p).

This integer x is called the inverse of a.

For instance, let’s try and find the inverse of 3 modulo 7. Write down the first (p − 1)
multiples (why first (p − 1)?) and check:

3 × 1 ≡ 3, 3 × 2 ≡ 6, 3×3≡2 (mod 7)
3 × 4 ≡ 5, 3 × 5 ≡ 1, 3×6≡4 (mod 7)

So, 5 is the inverse of 3.


We denote the inverse of a by a−1 . At times we even use a1 .
The existence of inverse allows us to divide! For instance, if b 6≡ 0 (mod p), then
a
≡ a · b−1 (mod p).
b
For instance, check the following are true:
2 3 20 −1
≡ 2 · 3−1 ≡ 3 (mod 7), ≡ 3 · 8−1 ≡ 3 (mod 7), ≡ ≡3 (mod 7). (2.1)
3 8 46 2
Now if we want to solve the equation ax ≡ b (mod p) with a 6≡ 0 (mod p), we can easily do
so. The solution is x ≡ ab = b · a−1 (mod p).

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 52
2. Modular Arithmetic Basics

Let me clear a possible confusion at this point. No, inverses do not always exist. For
example mod 6, we don’t have an inverse of 2 since:

2 × 1 ≡ 2, 2 × 2 ≡ 4, 2 × 3 ≡ 0 (mod 6)
2 × 4 ≡ 2, 2 × 5 ≡ 4 (mod 6)

We observe that 1 never appears, hence 2 does not have an inverse here. So modulo 6, we
cannot divide by 2.
Thus, the fact that an inverse always exists modulo a prime is very special (and useful).
I hope the above example helps you appreciate Theorem 2.7.1.

2.7.1 Inverses behave like fractions


As if the existence of an inverse wasn’t special enough, we also have the fact that inverses add
and multiply like fractions. This basically means you can literally use inverses like fractions
without worrying! For instance, in normal fractions,
2 3 16 + 9 25
+ = = . (2.2)
3 8 24 24
Modulo 7, the left side is (using equation 2.1)
2 3
+ = 2 · 3−1 + 3 · 8−1 = 3 + 3 = 6 (mod 7).
3 8
The right side of 2.2 is
25 4
≡ ≡ 4 · 3−1 ≡ 6 (mod 7).
24 3
Thus, 2.2 holds modulo 7 too, despite the fact that these are not really fractions modulo 7.
In general:

Lemma 2.7.1 (Inverses add like Fractions). Let b, d 6≡ 0 (mod p). Then for any a, c, we
have
a c ad + bc
+ ≡ a · b−1 + c · d−1 ≡ (ad + bc) · (bd)−1 ≡ (mod p)
b d bd
just like normal fractions.

More important than the proof of this is the following:

Question 2.7.1. Convince yourself that this is not obvious.

If you truely believe that Lemma 2.7.1 is not obvious, then let me prove it for you.

Proof. Observe that

bd(a · b−1 + c · d−1 ) = bd(a · b−1 ) + bd(c · d−1 ) ≡ ad + bc (mod p).

Dividing both the sides by bd we get the result.

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 53
2. Modular Arithmetic Basics

Multiplication of inverses is also similar:

Lemma 2.7.2 (Inverses multiply like Fractions). Let b, d 6≡ 0 (mod p). Then for any a, c,
we have
a c ac
· ≡ (a · b−1 ) · (c · d−1 ) ≡ (ac) · (bd)−1 ≡ (mod p)
b d bd
just like normal fractions.

Here’s an example: In normal fractions,

2 3 1
· = . (2.3)
3 8 4
Viewing these fractions as inverse, the left side modulo 7 is

2 3
· ≡ (2 · 3−1 ) · (3 · 8−1 ) = 3 · 3 ≡ 2 (mod 7)
3 8
On the other hand, the right side of of 2.3 is

1
≡ 4−1 ≡ 2 (mod 7).
4
Thus, 2.3 holds modulo 7 too.
Proving Lemma 2.7.2 is rather easy and so I leave it as an exercise.

Problems for Practice


Problem 2.7.1. Prove Lemma 2.7.2.

Problem 2.7.2. Find the inverse of all {1, 2, 3, 4, 5, 6, 7, 8, 9, 10} modulo 11.

Problem 2.7.3. Show that 0 does not have an inverse modulo p. What about p?

(If you say this is because 1/0 is not defined or is ∞, then that argument is true for
normal fractions, but not here. This proof fails modulo p because inverses aren’t exactly
division. Find a different proof.)

Problem 2.7.4. Prove that if a 6≡ 0 (mod p), then

ap−2 ≡ a−1 (mod p).

Problem 2.7.5. Prove that the inverse of an is the nth power of the inverse of a. That is,

(a−1 )n ≡ (an )−1 (mod p).

Using this, find the inverse of 256 modulo 47.

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 54
2. Modular Arithmetic Basics

2.8 Simple Properties of Inverses and Wilson’s Theo-


rem
I will talk about some simple properties of inverses here. Firstly note that an inverse is
unique. What I mean is a−1 is unique modulo p. For instance you can’t have both 2a ≡ 1
(mod p) AND 7a ≡ 1 (mod p). The number x such that ax ≡ 1 (mod p) would be unique.
The reason is simple. If ax ≡ 1 (mod p) and ay ≡ 1 (mod p) for 0 ≤ x, y ≤ p − 1, then
ax ≡ ay =⇒ p | a(x − y). As gcd(a, p) = 1, hence p | x − y. But 0 < x − y < p so this is
impossible.
Another simple property is that if a is the inverse of b then b is the inverse of a. That is,

a ≡ b−1 =⇒ a−1 ≡ b (mod p).

Don’t read ahead till this feels obvious to you too!


So we can basically pair up numbers with their inverses. For example modulo 11, we
have the following pairs:

{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} =⇒ (1, 1), (2, 6), (3.4), (5, 9), (7, 8), (10, 10). (2.4)

Wait, the pairs (1, 1), (10, 10) have the same elements. So now we ask when is a the inverse
of a. This is the same as saying a · a ≡ 1 (mod p), i.e. p | (a − 1)(a + 1). Hence p | (a − 1) or
p | (a + 1) (why?). This is the same as saying a ≡ 1 or a ≡ −1. So these are the only cases
in which a is the inverse of a.
Thus, if we ignore these bad pairs, then in any pair (a, b) we would have a 6= b. Further
every remainder mod p is in some pair. So, if we multiply ALL of them, we get something
very interesting:

2 · 3 · 4 . . . 9 = (2 · 6) · (3 · 4) · (5 · 9) · (7 · 8)
= 1 · 1 · 1 · 1 · 1 = 1 (mod 11).

So if we multiply both the sides by 1 · 10 ≡ −1 (mod 11), we find

10! ≡ −1 (mod 11).

Interesting right? This is a special case of a much more general result, the famous Wilson’s
theorem:

Theorem 2.8.1 (Wilson’s Theorem). Let p be a prime. Then

(p − 1)! ≡ −1 (mod p).

This is proved exactly in the same way as we did for 10!, that is pairing up with inverses.
This is a very cool theorem and probably the most used one when it comes to factorials
modulo something.

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 55
2. Modular Arithmetic Basics

Actually, I would be lying to you if I said this was Wilson’s theorem. There’s a bit more
to it. It also says that if n is any natural satisfying (n − 1)! ≡ −1 (mod n), then n must
be a prime. Woah. This is one of the rare criterions/formulas that we have for testing if a
number is prime. So if you want to check if n is a prime, then you just calculate (n − 1)!
and check if it’s −1 modulo n.
Sadly, finding (n − 1)! is hard and not feasible even for a computer for large values of n.
To get an idea of how large factorials get, 100! has 158 digits. Nonetheless, I will write the
full theorem here:

Theorem 2.8.2 (Wilson’s Theorem). For any integer n, we have

(n − 1)! ≡ −1 (mod n)

if and only if n is a prime.

Note here the ”if and only if” means two things: if (n − 1)! ≡ −1 (mod n), then n is a
prime, and also if n is a prime, then (n − 1)! ≡ −1 (mod n).

Practice Problems
Problem 2.8.1. Prove that if n is any natural satisfying (n − 1)! ≡ −1 (mod n), then n
must be a prime.

Problem 2.8.2. Let p be a prime. Show that the remainder when (p − 1)! is divided by
p(p − 1) is p − 1.

Problem 2.8.3. Let n be an integer. Calculate

gcd(n! + 1, (n + 1)!).

2.9 General Equal Sets


Earlier we got
aS ≡ S (mod p)
for any a with gcd(a, p) = 1 and S = {1, 2, . . . , p − 1}. Let’s try to generalize this to any
integer n instead of just a prime p. Note that the only fact we used in the proof was that a
and any element in S is coprime to p. (Confirm this by reading the proof again.)
I will leave it as an exercise to prove this, but here’s the full result:

Theorem 2.9.1 (General Equal Sets). Let n be any integer. Let S be the set of integers less
than n and relatively prime to n. Let a be any integer coprime to n. Then

aS ≡ S (mod n).

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 56
2. Modular Arithmetic Basics

The proof is exactly the same. Note that S is not {1, 2, 3, . . . , n − 1}. It is only the set
of integers coprime to n. Note that 1 ∈ S always holds (why?).
For example, if n = 15 and a = 4, then S = {1, 2, 4, 7, 8, 11, 13, 14}. So
4S ={4, 8, 16, 28, 32, 44, 52, 56}
≡{4, 8, 1, 13, 2, 14, 7, 11} (mod 15).
Check that the second set is the same as S. Now we will do exactly what we did before to
obtain general Fermat’s Little Theorem and general Inverses. Before we move on, let me
just clarify the following:
Definition 2.9.1. The set S is called a reduced residue system modulo n.

2.10 Euler’s Theorem


We obtained Fermat’s theorem by multiplying the elements of aS and S and equating them.
Let’s do the same here. Let |S| be the number of elements in S. Then
(a · 1) . . . (a · (n − 1)) ≡ 1 · · · (n − 1) (mod n).
Hence, Y Y
a|S| i≡ i (mod n).
1≤i<n 1≤i<n
gcd(i,n)=1 gcd(i,n)=1

The product here means the product of all numbers between 1, n that are coprime to n.
Again, we can cancel this product from both the sides using Problem 2.4.8 since it is
coprime to n (why?). Thus we get
a|S| ≡ 1 (mod n) for all a coprime to n (2.5)
This is cooler than Fermat’s little theorem since we have a general mod here.
Question 2.10.1. Check that when n = p is a prime, we have S = {1, 2, 3, . . . , p − 1} and
hence |S| = p − 1 in that case. Thus confirm that this result implies Fermat’s Little theorem
and hence is more general.
For instance, when n = 15, we have S = {1, 2, 4, 7, 8, 11, 13, 14}, and so |S| = 8. So, for
any a coprime to 15 we have a8 ≡ 1 (mod 15). For instance check that 118 ≡ 1 (mod 15).
However, this would be better if we had a formula for |S| in general. Turns out, mathe-
maticians left nothing hanging. Here’s what we are looking for:

2.10.1 Euler’s Totient Function


Recall that S was the set of integers less than n coprime to n. So we need to find how many
numbers less than n are coprime to it. This function was discovered by Euler, and is called
Euler’s Totient Function1
1
Fun Fact: even though Euler was the first one to use this function (officially), it took over 100 years for
the current notation and name to be coined!

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 57
2. Modular Arithmetic Basics

Definition 2.10.1. Let n be a positive integer. The function ϕ(n) is called Euler’s totient
function, and it denotes the number of positive integers less than n that are coprime to it.

Question 2.10.2. Find ϕ(2), ϕ(3), ϕ(4), ϕ(5), ϕ(6), ϕ(7), ϕ(8), ϕ(9) and ϕ(10).

Question 2.10.3. Show that ϕ(p) = p − 1 when p is a prime.

How do we find ϕ(100)?


Ok, I won’t trouble you much. I would just give you the formula.

Theorem 2.10.1 (Euler’s Totient Function). Let n = pα1 1 pα2 2 . . . pαk k be its prime factoriza-
tion. Then     
1 1 1
ϕ(n) = n 1 − 1− ... 1 − .
p1 p2 pk

Another way of writing is (which is easier to use)

ϕ(n) = pα1 1 −1 pα2 2 −1 . . . pαk k −1 · (p1 − 1) · (p2 − 1) · · · · (pk − 1).

The way I like to remember it is that for each prime p, reduce the power of p by 1 and
multiply by (p − 1).
This formula is derived by a lemma, that is incredibly useful in itself so I will mention it
here:

Lemma 2.10.1 (ϕ is multiplicative). For any two coprime integers m, n, we have

ϕ(mn) = ϕ(m)ϕ(n).

People often forget the coprime part. Don’t make the same mistake!

Comment 2.10.1: A function f : N → C is called multiplicative if

f (mn) = f (m)f (n) for all coprime m, n.

It is called completely multiplicative if

f (mn) = f (m)f (n) for all m, n.

We will talk about these more in the chapter on arithmetic functions.

Back to our previous discussion, 2.5 gives us the so called Euler’s Theorem:

Theorem 2.10.2 (Euler’s Theorem). Let n ≥ 2 be an integer and a be any integer coprime
to n. then
aϕ(n) ≡ 1 (mod n).

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 58
2. Modular Arithmetic Basics

Problems for Practice


Problem 2.10.1. Find 298 (mod 33)

Problem 2.10.2. Find 530 modulo 62.

Problem 2.10.3. What happens if gcd(a, n) 6= 1? Does there exist any integer m such that
am ≡ 1 (mod n)?

Problem 2.10.4. Show that n | 2n! − 1 for all odd n.

2.11 General Inverses


Look again at Theorem 2.9.1. Using that we obtain that there is some integer x ∈ S for which
ax ≡ 1 (mod n). We call x the inverse of n. Remember the condition that gcd(a, n) = 1.
Thus:

Theorem 2.11.1 (General Inverses). Let n ≥ 2 be any positive integer. Then every number
a with gcd(a, n) = 1 has an inverse, that is a number x such that

ax ≡ 1 (mod n).

We write x = a−1 .

This is an amazing theorem. We can now divide modulo any number, well almost. In
fact, we have only proved that if gcd(a, n) = 1, then a has an inverse. What if gcd(a, n) 6= 1?
Does an inverse exist in that case?
Turns out the answer is no. Let’s take an example. Suppose n = 9 and a = 3. Then

3 × 1 ≡ 3, 3 × 2 ≡ 6, 3 × 3 ≡ 0 (mod 9)
3 × 4 ≡ 3, 3 × 5 ≡ 6, 3 × 6 ≡ 0 (mod 9)
3 × 7 ≡ 3, 3 × 8 ≡ 6, 3 × 9 ≡ 0 (mod 9)

We do not find a 1 in there, so 3 does not have an inverse modulo 9. So we have

Lemma 2.11.1 (Inverses don’t always exist). If n is a natural number, and a is an integer,
then a has an inverse modulo n if and only if gcd(a, n) = 1. In particular, if gcd(a, n) > 1,
then a does not have an inverse.

Problems for Practice


Problem 2.11.1. Find the inverse of all {1, 3, 5, 7} modulo 8. What do you observe? Can
you explain this?

Problem 2.11.2. Does there exist an inverse for 5 modulo 10? What about 4?

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 59
2. Modular Arithmetic Basics

Problem 2.11.3. Show that gcd(a−1 , n) is also 1.

Problem 2.11.4. Prove that if gcd(a, n) 6= 1, then a cannot have an inverse.

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 60
2. Modular Arithmetic Basics

2.12 Extra Results as Problems


It should not be surprising that there are a lot of interesting results in modular arithmetic.
We present a few as problems here.

Example 2.12.1

Let a, m, n be integers. Suppose d sastifies

am ≡ 1 (mod d) and an ≡ 1 (mod d).

Then,
agcd(m,n) ≡ 1 (mod d).

This is very useful, and is just a modular analgoue of Example 1.10.4 (see comments
below). However, proving this using modular arithmetic is easier. Using Bézout’s lemma,
we find x, y ∈ Z such that mx + ny = gcd(m, n). So

amx+ny ≡ amx · any ≡ (am )x · (an )y ≡ 1 (mod d)

and we are done.

Comment 2.12.1: Let’s try to prove Example 1.10.4 using this. Suppose d =
gcd(am −1, an −1). To show d = agcd(m,n) −1, we show agcd(m,n) −1 | d and d | agcd(m,n) −1.
The former is easier to prove: just note that agcd(m,n) − 1 divides both am − 1, an − 1,
hence it divides their gcd d. Next, since

am ≡ 1 (mod d) and an ≡ 1 (mod d),

the above example problem tells us that d | agcd(m,n) − 1. Hence we conclude d =


agcd(m,n) − 1.

Example 2.12.2

Suppose a, b, d ∈ Z and n ∈ N such that ad ≡ bd (mod n). Show that


 
n
a ≡ b mod .
gcd(n, d)

For example, 6 ≡ 2 (mod 4) =⇒ 3 ≡ 1 (mod 2), not 3 ≡ 1 (mod 4). In other words,
if we want to cancel out a common factor of a, b, we would also have to reduce the thing
inside mod. In particular, note that ka ≡ kb (mod n) implies a ≡ b (mod n) if and only if
gcd(k, n) = 1 (this is Problem 2.4.8).
Proof. We have n | d(a − b). Now, the d contributes only to gcd(d, n) in this divisibility.
Hence, n/ gcd(d, n) divides a − b, as needed.

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 61
2. Modular Arithmetic Basics

A more formal argument would be to write n = gn∗ , d = gd∗ with g = gcd(n, d). Then
n∗ | d∗ (a − b) but since n∗ , d∗ are coprime, hence n∗ | a − b (by Euclid’s lemma, Example
1.8.2).

Example 2.12.3 (Freshman’s Dream)

Let a.b be integers and p be a prime. Prove that

(a + b)p ≡ ap + bp (mod p).

The is mockingly called the Freshman’s dream because (x + y)n = xn + y n is a very


common mistake made by Freshmen. However, their mistake is not a mistake anymore
modulo p.
The proof of this is to use the binomial theorem:
 
p p p p−1
(a + b) = a + a b + · · · + bp (mod p).
1

Now, if you try to take examples, you will observe that p divides all the binomial coefficient
above. This is in fact true and a very useful result:
 
p
p| ∀1 ≤ k ≤ p − 1.
k

The proof of this is not very hard, since kp = k!(p−k)!


p!

and the numerator is divisible by p,
while the denominator isn’t. So, using this we obtain that all the coefficients are 0 modulo
p, and so we get (a + b)p ≡ ap + bp (mod p).

Problem 2.12.1. Use Freshman’s dream and induction to prove Fermat’s Little Theorem.

Comment 2.12.2 (Just some facts): The result (a + b)p = ap + bp is not true over
integers, but is true over integers modulo p. We often denote the set of integers modulo
p by Z/pZ or Fp (we will use the second notation in this book). If we think of Fp as a
”structure”, i.e. a system of certain numbers, then this identity holds over this system.
Turns out there are more interesting and general systems over which this holds true.
However, they are beyond the scope of this book.
Also, if we define a function σ over Fp by saying σ(t) = tp , then we just showed
σ(a + b) = σ(a) + σ(b). The function σ is called a Frobenius endomorphism and is
also defined over general systems about which we talked above.

Since I mentioned a very convenient notation in the comments, I would highlight it here
too:

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 62
2. Modular Arithmetic Basics

Definition 2.12.1. The set of integers modulo p is denoted by Fp , where p is a prime. It is


also denoted by Z/pZ.

Here, it is important to note that p is a prime. Writing F10 is an incorrect use of the
notation. However, you can use Z/10Z to denote the set of integers modulo 10. The notations
might seem obscure at this point, however it is explained better using the notion of fields
and quotient rings from abstract algebra. So if you fight the notation right now, you would
be contradicting yourself a few years later in college. So just use the notation blindly, as it
is convenient.

Problem 2.12.2. Use induction to show that


i i i
(a + b)p ≡ ap + bp (mod p)

for any prime p and any non-negative integer i.

Example 2.12.4

Let p be a prime. Prove that

xp − x = x(x − 1)(x − 2) . . . (x − (p − 1)) (mod p)

for any x.

Just see that for any x, one of x, x − 1, . . . , x − (p − 1) is 0 modulo p. Hence, the right
side becomes 0 modulo p. What about the left side? Well, that is zero for any residue
too by Fermat’s Little Theorem! Hence, if we define the polynomials f (x) = xp − x and
g(x) = x(x − 1) . . . (x − (p − 1)), then f (x) ≡ g(x) (mod p) for any x.
If you see carefully, this doesn’t say that the polynomials f (x), g(x) are the same (i.e.
have the same coefficients modulo p), it merely says it would give the same value. For
instance, xp ≡ x (mod p) is true for all x value-wise, but the polynomials xp and x are
obviously different.
So the natural question now is if f (x), g(x) are equal as polynomials too. We answer this
question in the special section of the chapter ”Modular Arithmetic Advanced”.

Example 2.12.5 (Wolstenholme’s Theorem)

Let p > 3 be a prime. Prove that if


1 1 1 m
1+ + + ··· + = ,
2 3 p−1 n

where m, n are coprime integers, then p2 | m.

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 63
2. Modular Arithmetic Basics

The above theorem can be stated by saying


1 1 1
1+ + + ··· + ≡0 (mod p2 ) (2.6)
2 3 p−1
since denominators make sense as long as they are coprime to p2 (why?). For instance, if
p = 7, then this says that 49/20 is divisible by 49.
We have to prove Equation 2.6. A common theme in problem solving is to solve a
simplified problem. In this case, we try to prove Equation 2.6 modulo p instead of p2 .
Suppose p = 7. Then
1 1 1 1 1 49
1+ + + + + = .
2 3 4 5 6 20
If we try to find this sum in a different way, we must look at it as an algebraic sum instead of a
number theoretic one. One common trick in such algebra problems is Gaussian pairing, which
is pairing of ”opposite terms” (the same technique Gauss used to find sum of 1+2+· · ·+100,
the old folklore). This works here if we form the pairs 1i + p−i 1
since the numerator is p. For
instance, when p = 7,
     
1 1 1 1 1 1 1 7 7 7
1 + + ··· + = 1 + + + + + = + + .
2 7 6 2 5 3 4 1×6 2×5 3×4
Clearly, each term is divisible by 7 and hence so is their sum!
In general, since p > 2, p − 1 is even and we can pair off terms smoothly. Writing our
observation succinctly using the sigma notation, we find
p−1 p−1
p−1 2   2
X 1 X 1 1 X 1
= + =p ≡0 (mod p).
i=1
i i=1
i p−i i=1
i(p − i)

And that’s how we get the result modulo p. What about p2 though? We now only need to
show
p−1
2
X 1
≡0 (mod p).
i=1
i(p − i)
Well, at this point we must try something new. First of all, since (p − i) ≡ −i (mod p),
hence each denominator above can be replaced by −i2 . Now, pairing did work well for us,
however it complicated one thing, the number of terms. Luckily, we can multiply by 2 to
restore (why?). So
p−1
2 p−1
X 1 X1
2 ≡ (mod p).
i=1
i(p − i) i=1
i2
Since we are dealing with terms of the form 1/i = i−1 , hence there is no way we can miss
inverses; they can easily help us get rid of the fractions. However, we don’t know what i−1
would be. Let’s fall back to our example of p = 7. We can calculate
1 1 1 1 1 1
2
+ 2 + 2 + 2 + 2 + 2 ≡ 12 + 42 + 52 + 22 + 32 + 62 (mod 7).
1 2 3 4 5 6
c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 64
2. Modular Arithmetic Basics

We immediately observe that each residue appears in the sum. Luckily, observing this
fact is harder than proving it. The proof just follows since {1−1 , 2−1 , . . . , (p − 1)−1 } ≡
{1, 2, . . . , p − 1} (mod p) (why? If i−1 ≡ j −1 , then cross multiplying gives i ≡ j (mod p)).
So
1 1 1
2
+ 2
+ 2
≡ −(12 + 22 + · · · + (p − 1)2 )
1 2 (p − 1)
(p − 1)p(2p − 1)
=− (mod p),
6
where we used the sum of first n squares formula. We must show the above is 0 mod p.
But since p > 3, hence gcd(p, 6) = 1. Thus p has no contribution in making p(p−1)(2p−1) 6
an
(p−1)(2p−1)
integer, and hence 6
is also an integer. So the right side is p times an integer, which
is thus 0 (mod p). So we are done!
Too much discussion happened here. Let’s try and neatly summarize our argument into
one equation! (note where we used = and where ≡, denoting where we used algebraic facts
vs number theoretic facts)
p−1
X 1 X 1 1

2 = +
i=1
i i=1
i p−i
p−1
X p
=
i=1
i(p − i)
p−1
X −1
≡p
i=1
i2
p−1
X
≡ −p i2
i=1
2
p (p − 1)(2p − 1)
=− ≡0 (mod p2 ).
6
Can you link each line above with our discussion?

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 65
2. Modular Arithmetic Basics

2.13 Example Problems


I will try to cover a variety of problems in this section. Some may be clever, some may be
boring problems with not much insight. However, you should learn to face the truth!

Example 2.13.1 (USAMO 1991/3)

Show that, for any fixed integer n ≥ 1, the sequence


2 22
2, 22 , 22 , 22 , . . . (mod n)

is eventually constant.
(The tower of exponents is defined by a1 = 2, ai+1 = 2ai . In other terms, we start
22 4
working from the top, for instance 22 = 22 = 216 = 65536.)

For convenience, define ai to be the ith term of the sequence. Firstly, assume n is odd.
Since 2ϕ(n) ≡ 1 (mod n), hence if we can ak ≡ ak+1 ≡ ak+2 ≡ . . . (mod ϕ(n)) for some k,
we would get
2ak ≡ 2| a{z
|{z}
ak+2
} ≡ 2| {z } ≡ . . . (mod n),
k+1

=ak+1 =ak+2 =ak+3

which is what we want. So if we can show if the sequence hai i eventually becomes constant
modulo ϕ(n), we can conclude that it eventually becomes constant modulo n as well. So we
have to prove the same problem for ϕ(n) instead.
The key observation now is ϕ(n) < n. So we have reduced the problem from case n to a
smaller case. Hence, we can use (strong) induction! Here’s how it goes:

Proof. Check the base case of n = 1, and assume the result till some n − 1. If n is odd, we
can reduce the problem to smaller case ϕ(n), for which it is true by the induction hypothesis.
We just have to manage n even now. In this case, we try to eliminate the ”even part” of n
and work. So if n = 2m n∗ with n∗ odd, then pick k large enough such that ak > m. So

2ak ≡ 2ak+1 (mod n) ⇔ 2ak −m ≡ 2ak+1 −m (mod n∗ )

and again use the induction hypothesis as n∗ < n (here we used the result from Example
2.12.2).

Sometimes, simple modular considerations can be useful:

Example 2.13.2

Given
34! = 295232799039a041408476186096435b0000000,
in decimal representation, find the numbers a and b.

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 66
2. Modular Arithmetic Basics

Proof. We know that 9|34!. Also we know from the rule of divisibility by 9 that for all
naturals n, n ≡ S(n) (mod 9), where S(n) is the sum of digits of n. Hence, 9|a + b + 136
and so a + b ∈ {8, 17}, as 0 ≤ a, b ≤ 9.
We also know that 11|34!. Also, a number modulo 11 is congruent to the alternating sum
of the digits in the number, read from left to right. Therefore, 11|(77+a)−(59+b) = 18+a−b
and so a − b ∈ {−7, 4} as 0 ≤ a, b ≤ 9.
Now, note that a + b and a − b have the same parity. Hence, the only possibilities are
(a + b, a − b) = (8, 4) and (17, −7), and the two cases yield (a, b) = (6, 2) or (a, b) = (5, 12),
respectively. But since a, b ≤ 9, hence the second case is impossible. Thus, (a, b) = (6, 2)
proving the claim.

Another example where modular constraints help us bound things:

Example 2.13.3 (St. Petersburg 2008)

Given three distinct natural a, b, c show that


a+b+c
gcd(ab + 1, bc + 1, ca + 1) ≤
3

Proof. Suppose d = gcd(ab+1, bc+1, ca+1). Then ab, bc, ca ≡ −1 (mod d), and so ab−bc =
b(a − c) ≡ 0 (mod d). Now if b, d have a common factor, say p > 1, then p | d | ab + 1.
Combining with p | b, we get p | ab + 1 − b(a) = 1, a contradiction. Hence b, d are coprime
and so d | a − c.
Similarly, d | a − b, b − c. Thus, a ≡ b ≡ c (mod d). Now, assume without loss of
generality that a > b > c (strict inequalities since they are given to be distinct). Hence
a ≥ b + d ≥ c + 2d. So
a+b+c
a + b + c ≥ 3a + 3d ≥ 3d =⇒ ≥ d.
3
Hence we are done.

Not all problems are nice and sweet, some may involve simple ideas with which you work
a lot, typically means a lot of case work. For instance the following:

Example 2.13.4 (Azerbaijan Balkan Math Olympiad Third TST 2015)

Find all natural numbers n for which there exist primes p and q such that the following
conditions are satisfied:

1. p + 2 = q, and

2. 2n + p and 2n + q are both primes

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 67
2. Modular Arithmetic Basics

Proof. We will show that such primes exist if and only if n ∈ {1, 3}. By these conditions,
we have that (p, p + 2, p + 2n , p + 2n + 2) are all primes.
Clearly, p 6= 2 because else q = 4, which is not a prime. Let us assume for the moment
that p 6= 3. Thus, p ≥ 5.
1. If n is even, then (p, p + 2, p + 2n , p + 2n + 2) ≡ (p, p + 2, p + 1, p) (mod 3) and so at
least one of p, p + 2, or p + 2n is divisible by 3. This is clearly false since we assumed
these numbers are primes and p ≥ 5.
2. If n is odd, then (p, p + 2, p + 2n , p + 2n + 2) ≡ (p, p + 2, p + 2, p + 1) (mod 3) and so at
least one of p, p + 2, or p + 2n + 2 is divisible by 3, and since they are all primes, one
of them must be 3. This is again a contradiction because we assumed p ≥ 5.
Hence, we must have p = 3 and (3 + 2n , 5 + 2n ) is a pair of primes. It is easy to see that
this condition is satisfied for n = 1 and n = 3 but not for n = 2. We will show that there is
no n > 3 that satisfies this condition. First, notice that if n > 3, then
5 + 2n > 3 + 2n > 13.
If n is even, say n = 2z, then 5 + 2n = 5 + 4z ≡ 5 + 1 ≡ 0 (mod 3), but since 5 + 2n > 3,
this number cannot be a prime, a contradiction. Thus, n is odd. Set n = 2k + 1 for some
integer k.
If k is even, then
3 + 2n = 3 + 2 · 2n−1 = 3 + 2 · 4k
≡ 3 + 2 · (−1)k
≡ 3 + 2 ≡ 0 (mod 5),
which is a contradiction because 3 + 2n > 5. So, k is odd. Set k = 2r + 1 for some integer
r, and so n = 4r + 3.
If r ≡ 1 (mod 3), write r = 3z + 1. Then, we have
5 + 2n = 5 + 24r+3 = 5 + 8 · 16r
≡ 5 + 2r
≡ 5 + 23z+1
≡ 5 + 2 · 8z
≡ 5 + 2 ≡ 0 (mod 7),
and we get a similar contradiction to the ones previous cases.
If r ≡ 2 (mod 3), say r = 3z + 2, then
3 + 2n = 3 + 24r+3 = 3 + 8 · 16r
≡ 3 + 2r
≡ 3 + 23z+2
≡ 3 + 4 · 8z
≡ 3 + 4 ≡ 0 (mod 7),

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 68
2. Modular Arithmetic Basics

a contradiction.
This means that 3|r. Write r = 3s for some integer s so that n = 12s + 3. Thus,

5 + 2n = 5 + 212s+3
s
= 5 + 8 · 212
≡ 5 + 8 ≡ 0 (mod 13),

a contradiction.
Hence, we have exhausted all the possibilities and so n = 1 and n = 3 are the only
possible solutions.

Finally, we look at an amazing combinatorial-number theory problem. Euclid gave a


construction for showing the infinitude of primes. Somebody made a problem out of that
construction.

Example 2.13.5

Let P be the set of all prime numbers over naturals. Let M be a subset of P with at
least 3 elements. Choose any proper subset A of M. Consider the number
Y
nA := −1 + p
p∈A

Suppose that any prime divisor of nA lies in M for all A ⊂ M.


Show that M ≡ P.

We start by trying to manually show each prime is in M, at least for as many primes as
we can. Firstly, M has at least 3 elements. So choose an odd prime p ∈ M. Then n{p} is
even and so 2 ∈ M.
Next, if a prime p of the form 3k + 1 lies in M, then n{p} is divisible by 3. Otherwise
there exists a prime p of the form 3k + 2 and so n{2,p} = −1 + 2p is divisible by 3. Thus, in
either case we get that 3 ∈ M.
Then n{2,3} = 5 implies that 5 ∈ M. Also, n{3,5} =⇒ 7 ∈ M. The problem has the same
construction as that of Euclid’s. So this problem is screaming at us to try to do what he
did, show that the ”set” is infinite; in case the set of primes, and in our case the set M.
Claim. M is an infinite set
Proof. Assume on the contrary, and set M = {p1 , p2 , · · · pn }. We can’t directly consider nM
since the subset we choose must be a proper subset.
Hence, choose S = {p1 , p2 , · · · , pi−1 , pi+1 , · · · , pn }, i.e. we have removed pi from M. Let
P be the product of the elements of M. Then every factor of nS must be in M, and so we
must have
P
− 1 = pai for some a
pi
c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 69
2. Modular Arithmetic Basics

This is true because gcd(nS , pj ) = 1 for all j 6= i. Now this holds for all primes pi ∈ M. We
act greedily and choose pi = 2. Then
P
− 1 = 2a
2
Note that 7|P since 7 ∈ M. Hence considering this equation modulo 7 yields

2a ≡ −1 (mod 7)

It is easy to see that this has no solutions and so we are done.


(We could also have done this mod 15 as 3, 5 ∈ M.)
Now we just need to show that given any prime q, there exists some good set of primes
A from M such that q|nA . The best we can do is to choose a set of equal primes from M,
but this is not possible since we can’t use repeated elements. But we can fix this idea.
Note that M is infinite so mod q some residue occurs infinitely many times in M. Suppose
that p1 ≡ p2 ≡ · · · modulo q. Then take A to be the first q − 1 elements from pi . Then

nA ≡ pq−1
1 −1≡0 (mod q)

and we are done!

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 70
2. Modular Arithmetic Basics

2.14 Practice Problems


Problem 2.14.1. How many prime numbers p are there such that 29p + 1 is a multiple of
p?

Problem 2.14.2 (Useful Result). Let p be a prime and 0 ≤ k ≤ p − 1 be an intger. Prove


that  
p−1
≡ (−1)k (mod p).
k
Hints: 180

Problem 2.14.3 (IMO 1979/1). Let a and b be natural numbers such that
a 1 1 1 1 1
= 1 − + − + ··· − + .
b 2 3 4 1318 1319
Prove that a is divisible by 1979. (Note: 1979 is a prime) Hints: 350 407

Problem 2.14.4 (RMO 2016 P62 ). Let {a1 , a2 , a3 , . . . , } be a strictly increasing sequence
of positive integers in an arithmetic progression. Prove that there is an infinite subsequence
of the given sequence whose terms are in a geometric progression. Hints: 288

Problem 2.14.5. Let f (x) be a polynomial with integer coefficients. Show that there does
not exist a N such that f (x) is a prime for all x ≥ N. In other words, f (x) is not eventually
always a prime. This problem shows that prime numbers don’t follow any polynomial pattern
either. Hints: 308

Problem 2.14.6 (IMO 2005/4). Determine all positive integers relatively prime to all the
terms of the infinite sequence
an = 2n + 3n + 6n − 1, n ≥ 1.
Hints: 130

Problem 2.14.7 (IMO 1986/1). Let d be any positive integer not equal to 2, 5, or 13.
Show that one can find distinct a and b in the set {2, 5, 13, d} such that ab − 1 is not a perfect
square. Hints: 379 84 9

Problem 2.14.8. Let a and b be two relatively prime positive integers, and consider the
arithmetic progression a, a + b, a + 2b, a + 3b, . . .
1. (G. Polya) Prove that there are infinitely many terms in the arithmetic progression
that have the same prime divisors. Hints: 265 156 349
2. Prove that there are infinitely many pairwise relatively prime terms in the arithmetic
progression. Hints: 487 37
2
Regional Mathematical Oolympiad (the AIME of India)

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 71
2. Modular Arithmetic Basics

Problem 2.14.9. Prove that


1. every positive integer has at least as many divisors of the for 4k + 1 as divisors of the
form 4k + 3;
2. there exist infinitely many positive integers which have as many divisors of the form
4k + 1 as divisors of the form 4k + 3;
3. there exist infinitely many positive integers which have more divisors of the form 4k +1
than divisors of the form 4k + 3.
Hints: 457 116 435

Problem 2.14.10 (IberoAmerican 2005/3). Let p > 3 be a prime. Prove that if


p−1
X 1 m
p
=
i=1
i n

with gcd(m, n) = 1, then p3 | m. Hints: 357 207 284 231

Problem 2.14.11 (Sierpiński). Prove that for any positive integer s, there is a positive
integer n whose sum of digits is s and s | n. Hints: 200 397 197 Sol: pg. 280

Problem 2.14.12 (IMO Shortlist 2001 N4). Let p ≥ 5 be a prime number. Prove that
there exists an integer a with 1 ≤ a ≤ p − 2 such that neither ap−1 − 1 nor (a + 1)p−1 − 1 is
divisible by p2 . Hints: 204 218 467 66

Problem 2.14.13 (USAMO 2018/4). Let p be a prime, and let a1 , . . . , ap be integers.


Show that there exists an integer k such that the numbers
a1 + k, a2 + 2k, . . . , ap + pk
produce at least 21 p distinct remainders upon division by p. Hints: 194 241 115 Sol: pg. 281

Problem 2.14.14 (Balkan 2016/3). Find all monic polynomials f with integer coefficients
satisfying the following condition: there exists a positive integer N such that p divides
2(f (p)!) + 1 for every prime p > N for which f (p) is a positive integer. (A monic polynomial
has a leading coefficient equal to 1.) Hints: 341 321 67 436

Problem 2.14.15 (Iran 3rd round 2017 Numbers theory final exam P1). Let x and
y be integers and let p be a prime number. Suppose that there exist relatively prime positive
integers m and n such that
xm ≡ y n (mod p)
Prove that there exists an unique integer z modulo p such that
x ≡ zn (mod p) and y ≡ z m (mod p).
Hints: 20 365 108 Sol: pg. 281

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 72
2. Modular Arithmetic Basics

Problem 2.14.16 (IMO Shortlist 2015 N3). Let m and n be positive integers such that
m > n. Define
m+k
xk =
n+k
for k = 1, 2, . . . , n + 1. Prove that if all the numbers x1 , x2 , . . . , xn+1 are integers, then
x1 x2 . . . xn+1 − 1 is divisible by an odd prime. Hints: 104 328 192 471 Sol: pg. 281

Problem 2.14.17 (ELMO 2019/5). Let S be a nonempty set of positive integers such
that, for any (not necessarily distinct) integers a and b in S, the number ab + 1 is also in S.
Show that the set of primes that do not divide any element of S is finite. Hints: 233 30 10 480
Sol: pg. 282

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 73
2. Modular Arithmetic Basics

z More on Binomial Coefficients


One property of the binomial coefficient we have seen so far is
 
p
p| ∀1 ≤ k ≤ p − 1.
k

Another interesting property is Problem 2.14.2. In this special section, we discuss more.

Lucas’s Theorem
This theorem is very useful in understanding how binomial coefficients behave modulo primes.
But first, we do a problem:

Example 2.14.1

Show that the coefficients of a binomial expansion (a+b)n where n is a positive integer,
are all odd, if and only if n is of the form 2k − 1 for some positive integer k.

We want to show that


 
n
≡1 (mod 2) ∀ 0 ≤ m ≤ n
m

if and only if n = 2k − 1. (In other words, this tells us excatly which rows of the Pascal
triangle have all terms odd).
n

Suppose that n = 2k − 1. We want to show m is always odd. Since k is arbitrary,
our first bets should be on induction. Assume the result till k − 1 and let’s prove it for k.
Since we want to look at all the binomial coefficients at once, it is best to use the binomial
theorem, and the simplest expression is (X + 1)n . So
X n
X m = (X + 1)n
0≤m≤n
m
k −1
= (X + 1)2
k−1
= (X + 1)2·(2 −1)+1
 k−1
2
= (X + 1)2 −1 · (X + 1).

So, if we let t = 2k−1 −1, then (X +1)t = X t +at−1 X t−1 +· · ·+a1 X +1, where a1 , a2 , . . . , at−1
are all odd (why?). So
 2 2
2k−1 +1
(X + 1) · (X + 1) = X t + at−1 X t−1 + · · · + 1 (X + 1)

At this stage, we can simply look at the coefficient of X m (for any m) in the above expansion
and check it will be odd. For instance, the coefficient of X n−1 = X 2t would be (1 + 2at−1 ) (of

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 74
2. Modular Arithmetic Basics

course, you would need to elaborate more on why the coefficients wouldbe odd in a proper
n
proof, but I leave the details to the interested reader). However, since m was the coefficient
m
of X , hence this binomial coefficient is odd.
Thus, we have proven one direction of the problem. The other direction is more tricky,
n
which asks us to show that m is always odd for 1 ≤ m ≤ n implies n is of the form 2k + 1.
So I will just give the theorem’s statement:

Theorem 2.14.1 (Lucas’s Theorem). For non-negative integers m and n and a prime p,
the following congruence relation holds:
  Y k  
n ni
≡ (mod p)
m i=0
mi

where
n = nk pk + nk−1 pk−1 + · · · + n1 p + n0
and
m = mk pk + mk−1 pk−1 + · · · + m1 p + m0
n

are the base p expansions of m and n respectively. This uses the convention that m = 0 if
n < m.
ni

Note that this finishes the problem above easily, since we must have m i
must always
be odd impliying that ni = 1, which corresponds to n be of the form 11 . . . 1(2) = 2k − 1 for
some k.
The cleanest proof for this uses generating functions, with a method slightly similar to
the one we found for the previous problem. However, there are some technical details you
need to know to fully appreciate the proof, so you can find it in the special section of the
chapter: Integer Polynomials.
This theorem is very useful in proving some binomial identities. Here are some problems
to try:

Problem 2.14.18. Let a, b ∈ N and p be a prime. Prove that


   
pa a
≡ (mod p).
pb b

Problem 2.14.19. Find a formula for the number of entries in the nth row of Pascal’s
triangle that are not divisible by p, in terms of the base-p expansion of n.

2 Interesting Lemmas
In this part, we talk about two interesting properties related to the binomial coefficients.
p k

They give nice formulas for k and p .

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 75
2. Modular Arithmetic Basics

Lemma 2.14.1. Let p be an odd prime. Then


   
k k
≡ (mod p),
p p

where b•c represents the floor function (aka the greatest integer function).

This is not very tricky to prove, and very easy if you use Lucas’s theorem. So the proof
is left as an exercise. Another useful property is

Lemma 2.14.2. Let


(−1)k−1 p
 
1
≡ (mod p2 ).
k p k
The proof to this is pretty straightforward too:
 
1 p (p − 1)(p − 2) . . . (p − k + 1)
=
p k k(k − 1) . . . 1
(−1)(−2) . . . (−k + 1)

k(k − 1) . . . 1
1
= (−1)k−1 (mod p).
k
Here are two problems using the above lemma (note: they are challenging problems even
after using this lemma)

Problem 2.14.20 (ELMO 2009/6). Let p be an odd prime and x be an integer such that
p | x3 − 1 but p - x − 1. Prove that

x2 x3 xp−1
 
p | (p − 1)! x − + − ··· − .
2 3 p−1

Problem 2.14.21 (IMO Shortlist 2011 N7). Let p be an odd prime number. For every
integer a, define the number

a a2 ap−1
Sa = + + ··· + .
1 2 p−1
Let m, n ∈ Z, such that
m
S3 + S4 − 3S2 = .
n
Prove that p divides m.

c
Aditya Khurmi 2020. All rights reserved. (Published on 11/2020) 76

You might also like