Intro to Modular Arithmetic
Intro to Modular Arithmetic
CaptainFlint
May 30, 2015
Part I
Introduction
Numbers are sometimes thought of as they appear on the number line: stretching infinitely out in each
direction. The normal system of arithmetic is based on the ways numbers relate to each other on the
number line. Other times, numbers are thought of repeating in a cycle. For example, 6 A.M. is thought
of as the same time, even though it is never experienced more than once. In this article we will discover a
system of arithmetic using this number system.
Modular arithmetic is an arithmetic system using only the integers 0, 1, 2, . . . , a − 1. When we work this
way, we say we are working modulo a, and the modulus of the system is a.
Part II
Modular Congruences
We will start with a problem:
1 Problem
We have a clock with six numbers on its face: 0, 1, 2, 3, 4, and 5. The clock only hand moves clockwise from
0 to 1 to 2 to 3 to 4 to 5 and back again to 0.
1. What number is the hand pointing at after 12 ticks?
2. What number is the hand pointing at after 28 ticks?
3. What number is the hand pointing at after 42 ticks?
4. What number is the hand pointing at after 1337 ticks?
Solution: We list the first 30 numbers in the list and the first 30 positive integers side by side:
1 2 3 4 5 0 1 2 3 4 5 6
1 2 3 4 5 0 7 8 9 10 11 12
1 2 3 4 5 0 13 14 15 16 17 18
1 2 3 4 5 0 19 20 21 22 23 24
1 2 3 4 5 0 25 26 27 28 29 30
We can see that the answers to parts 1 and 2 are 0 and 4, respectively. We can also notice that each number
on the left grid is the remainder of each number on the right grid when divided by 6. Hence, we see that the
1
Introduction to Modular Arithmetic CaptainFlint Page 2
answer to part 3 is the remainder when 42 ÷ 6, which is 0, and that the answer to part 4 is 1337 ÷ 6, which
is 5.
2 Congruence
Two integers are said to be equivalent (or congruent) modulo a if their difference is a multiple of a. We
shorten ”modulo” to ”mod”, and use the symbol ≡ to denote congruence. For example,
12 ≡ 0 (mod 6) and 32 ≡ 16 (mod 4).
For integers x and y, y ≡ x (mod a) if and only if m | x − y. Hence, for an integer z, we have x − y = za.
Isolating z gives us z = x−ya . If z is an integer, then y ≡ x (mod a).
Also, for positive integers x and y, x ≡ y (mod a) if and only if
x = z1 a + w
y = z2 a + w
where z1 , z2 , and w are integers, and 0 ≤ w < a.
3 Exercises
3.1 Exercise 1
Are 31 and 24 congruent modulo 9?
3.2 Exercise 2
Are 45 and 15 congruent modulo 3?
Part III
Residues
4 Introduction
We say that b is the modulo-a residue of n when c ≡ b (mod a), and 0 ≤ b < a.
5 Residue Classes
We begin with a problem.
5.1 Problem
List the integers between -70 and 70 whose modulo 12 residues are 10.
5.2 Solution
An integer is congruent to 10 mod 12 if it can be written as 12a + 10 for any integer a. This gives us the
inequality
−70 < 12a + 10 < 70.
2
Introduction to Modular Arithmetic CaptainFlint Page 3
{−62, −50, −38, −26, −14, −2, 10, 22, 34, 46, 58}.
6 Exercises
6.1 Exercise 1
Determine the modulo-9 residue of each of the following.
1. 11
2. 45
3. 23
4. 434
5. 42
6. 1337
6.2 Exercise 2
Write each of the following integers in the form 3a + b, where a and b are integers and 0 ≤ b < 3.
1. 43
2. 4
3. 100
3
Introduction to Modular Arithmetic CaptainFlint Page 4
4. 98
5. 42
6. -34
7. 1337
6.3 Exercise 3
Show that if x ≡ y (mod a) and y ≡ z (mod a), then x ≡ z (mod a).
Part IV
Modular Addition & Subtraction
7 Introduction
Let a1 , a2 , b1 , and b2 be integers such that
a1 ≡ a2 (mod n)
b1 ≡ b2 (mod n).
We can add these, and get
a1 + b1 ≡ a2 + b2 (mod n).
7.1 Proof
From the definition of congruence, we have
a1 −a2 b1 −b2
n and n
8 Exercises
8.1 Exercise 1
Is 54 + 42 ≡ 2 + 14 (mod 8)?
4
Introduction to Modular Arithmetic CaptainFlint Page 5
8.2 Exercise 2
Is 69 − 45 ≡ 18 − 15 (mod 3)?
8.3 Exercise 3
Let a, b, and c be integers whose residues modulo 8 are 4, 5, and 7, respectively. Compute the residue of
a + b + c (mod 8).
Part V
Modular Multiplication
9 Introduction
Let a, b, c, and d be integers. If
a ≡ b (mod m)
c ≡ d (mod m),
then
ac ≡ bd (mod m).
9.1 Proof
Since m is a divisor of a − b and c − d, we have
a = b + xm
c = d + ym
ac = (b + xm)(d + ym)
= bd + bym + dxm + xym2
= bd + m(by + dx + xym).
ac − bd = bd + m(by + dx + xym) − bd
= m(by + dx + xym).
10 Exercises
10.1 Exercise 1
Is 9 · 43 ≡ 8 · 98 (mod 23)?
10.2 Exercise 2
Find the modulo 4 residue of 100!.
5
Introduction to Modular Arithmetic CaptainFlint Page 6
10.3 Exercise 3
The residues of 3 positive integers modulo 8 are 1, 4, and 7. Find the residue of their products modulo 8.
Part VI
Modular Exponentiation
11 Introduction
Let a and b be integers, and c be a natural number. If a ≡ b (mod m), then
ac ≡ bc (mod m).
11.1 Proof
We have a · a ≡ b · b (mod m) =⇒ a2 ≡ b2 (mod m). We can multiply factors of a and b to powers of a
and b to show that the next highest power of a and b are also congruent.
a · a2 ≡ b · b2 (mod m) =⇒ a3 ≡ b3 (mod m)
a · a3 ≡ b · b3 (mod m) =⇒ a4 ≡ b4 (mod m)
a · a4 ≡ b · b4 (mod m) =⇒ a5 ≡ b5 (mod m)
a · a5 ≡ b · b5 (mod m) =⇒ a6 ≡ b6 (mod m)
·
·
·
a · ac−1 ≡ b · bc−1 (mod m) =⇒ ac ≡ bc (mod m)
12 Exercises
12.1 Exercise 1
Is 2414 − 1514 divisible by 9?
12.2 Exercise 2
Find residue r such that 56001 ≡ r (mod 7).
Part VII
Modular Division
13 Introduction
There is no law of division in modular arithmetic. We can see this with the following example.
13.1 Example
We have the congruence
6 ≡ 16 (mod 10),
6
Introduction to Modular Arithmetic CaptainFlint Page 7
Part VIII
Modular Inverses
14 Introduction
The multiplicative inverse of an integer a (mod m) is the integer a−1 such that
15 Problems
15.1 Problem 1
15.1.1 Problem
Find the inverses of all mod 12 residues that have inverses.
15.1.2 Solution
We write out the entire modulo 12 multiplication table:
× 0 1 2 3 4 5 6 7 8 9 10 11
0 0 0 0 0 0 0 0 0 0 0 0 0
1 0 1 2 3 4 5 6 7 8 9 10 11
2 0 2 4 6 8 10 0 2 4 6 8 10
3 0 3 6 9 0 3 6 9 0 3 6 9
4 0 4 8 0 4 8 0 4 8 0 4 8
5 0 5 10 3 8 1 6 11 4 9 2 7
6 0 6 0 6 0 6 0 6 0 6 0 6
7 0 7 2 9 4 11 6 1 8 3 10 5
8 0 8 4 0 8 4 0 8 4 0 8 4
9 0 9 6 3 0 9 6 3 0 9 6 3
10 0 10 8 6 4 2 0 10 8 6 4 2
11 0 11 10 9 8 7 6 5 4 3 2 1
From this, we see that all modulo 12 residues that have inverses are 1, 5, 7, and 11, and that there exists no
inverses for residues 2, 3, 4, 6, 8, 9, and 10.
We can note that 1, 5, 7, and 11 are relatively prime to 12, and 2, 3, 4, 6, 8, 9, and 10 are not.
15.2 Problem 2
15.2.1 Problem
Prove that a−1 modulo n exists only if gcd(a, n) = 1.
7
Introduction to Modular Arithmetic CaptainFlint Page 8
15.2.2 Solution
If a−1 exist, it is a solution to the congruence ax ≡ 1 (mod n). Thus, for some value of x,
ax − yn = 1,
where y is an integer. We let z = gcd(a, n), which means that z | ax and z | yn. A divisor of two integers
is the divisor of their difference, which means that z | (ax − yn). Since ax − yn = 1, z | 1. The only integer
that is a divisor of 1 is 1, so z = 1. Therefore, a−1 exists if gcd(a, n) = 1.
16 Exercises
16.1 Exercise 1
Does 6 modulo 25 have an inverse? Why?
16.2 Exercise 2
Find all possible residues modulo 20 that have inverses.
Part IX
How to Find Modular Inverses
Let’s begin with a problem:
17 Problem
17.1 Problem
Find the inverse of 3 modulo 7.
17.2 Solution
We list the first few integers that are congruent to 1 (mod 7). They are
The term 15 is of the form 3x, where x = 5. Thus, the inverse of 3 modulo 7 is 5 .
This method seems tedious for larger moduli and inverses. We need a systematic way to find inverses.
8
Introduction to Modular Arithmetic CaptainFlint Page 9
18.2 Problem
18.2.1 Problem
Find the inverse of 37 modulo 97.
18.2.2 Solution
We turn this into the equation 37x + 97y = 1, and solve for x. Then, we divide 97 ÷ 37 to get a quotient
of 2 and a remainder of 23. We compute 37 ÷ 23, and get a quotient of 1 and a remainder of 14. Next,
we compute 23 ÷ 14, and we get a quotient of 1 and remainder 9. Dividing 14 ÷ 9, we get quotient 1 and
remainder 5. 9 ÷ 5 has a quotient of 2 and a remainder of 4. Finally, 5 ÷ 4 has a quotient 1 and remainder
1. From this we get the equations:
97 = 2 · 37 + 23
37 = 1 · 23 + 14
23 = 1 · 14 + 9
14 = 1 · 9 + 5
9=1·5+4
5 = 1 · 4 + 1.
We rearrange these equations to isolate the remainders:
23 = 97 − 2 · 37
14 = 37 − 1 · 23
9 = 23 − 1 · 14
5 = 14 − 1 · 9
4=9−1·5
1 = 5 − 1 · 4.
Substituting, we have:
1=5−1·4
= 5 − (9 − 1 · 5)
=2·5−9
= 2(14 − 1 · 9) − 9
= 2 · 14 − 3 · 9
= 2 · 14 − 3(23 − 1 · 14)
= 5 · 14 − 3 · 23
= 5(37 − 1 · 23) − 3 · 23
= 5 · 37 − 8 · 23
= 5 · 37 − 8(97 − 2 · 37)
= −8 · 97 + 21 · 37.
Hence, x = 21, which means that the inverse of 37 modulo 97 is 21 , or 21 · 37 ≡ 1 (mod 97).
19 Exercises
19.1 Exercise 1
Find the inverse of 5 modulo 6.
9
Introduction to Modular Arithmetic CaptainFlint Page 10
19.2 Exercise 2
Find the inverse of 19 modulo 21.
19.3 Exercise 3
Find x such that 17x ≡ 1 (mod 23).
Part X
Linear Congruences
20 Introduction
A linear congruence equation is a congruence that has a variable raised only to the first power. A linear
congruence can be expressed as
ax ≡ b (mod n),
where a and b are integers, a modulus n, and variable x. For example, 4x ≡ 3 (mod 6) is a linear congruence.
Let’s start by solving a few simple linear congruences, and then move on to some harder problems.
21 Problems
21.1 Problem 1
21.1.1 Problem
Find the values of x where 0 ≤ x < 5 that satisfy the following linear congruences:
1. x − 4 ≡ 0 (mod 5).
2. x − 1 ≡ 1 (mod 5).
3. x + 3 ≡ 1 (mod 5).
4. x + 12 ≡ 3 (mod 5).
21.1.2 Solution
1. Since addition is a valid operation in modular arithmetic, we can add 4 to both sides. Thus, we have
x − 4 + 4 ≡ 0 + 4 (mod 5) =⇒ x ≡ 4 (mod 5).
2. As before, we add 1 to both sides of the congruence, which gives x ≡ 2 (mod 5).
3. Since subtraction is a valid operation in modular arithmetic, we can subtract 3 from both sides. Thus,
we have x ≡ −2 ≡ 3 (mod 5).
10
Introduction to Modular Arithmetic CaptainFlint Page 11
21.2 Problem 2
21.2.1 Problem
Find the values of x where 0 ≤ x < 5 that satisfy the following linear congruences:
1. 3x ≡ 1 (mod 5).
2. 3x ≡ 2 (mod 5).
3. 2x ≡ 3 (mod 5).
4. 12x ≡ 4 (mod 5).
5. 2x − 4 ≡ 2 (mod 5).
21.2.2 Solution
1. We can’t divide both sides by 4, because there is no law of division in modular arithmetic. However, we
can multiply by the modular inverse of 3 (mod 5), which is 2. Multiplying, we have 6x ≡ 2 (mod 5).
Since 6 ≡ 1 (mod 5), we have 6x ≡ 1x ≡ x (mod 5). Thus, we have x ≡ 2 (mod 5).
2. In this part, we again multiply 3x ≡ 2 (mod 5) by 3−1 , which is 2. Thus, we have 6x ≡ 4 (mod 5) =⇒
x ≡ 4 (mod 5).
2x − 4 + 4 ≡ 2 + 4 (mod 5)
2x ≡ 6 (mod 5)
2x ≡ 1 (mod 5).
From these problems, we see that if the coefficient of the variable is relatively prime to the modulus, then
we can get rid of the coefficient by multiplying both sides of the congruence by the inverse of the coefficient.
22 Exercises
22.1 Exercise 1
Find all possible values of x such that 23x ≡ 14 (mod 15).
22.2 Exercise 2
Find all possible values of x such that 23x + 234 ≡ 12 (mod 15).
11
Introduction to Modular Arithmetic CaptainFlint Page 12
22.3 Exercise 3
Let y be a positive integer. Prove that if ay ≡ by (mod my) for integers a and b, then a ≡ b (mod m).
(Introduction to Number Theory)
Part XI
Systems of Linear Congruences
Let’s begin with some problems.
23.1.2 Solution
From the first congruence, we see that x is divisible by 2. From the second, we see that x is also divisible
by 5. Thus x is divisible by 10, or x ≡ 0 (mod 10) .
This problem was quite easy. Let’s try a harder one.
23.2 Problem 2
23.2.1 Problem
Find all possible values of x such that
x≡1 (mod 3)
x≡0 (mod 7)
23.2.2 Solution
From the second congruence, we see that x is divisible by 7. We list the first few nonnegative multiples of 7.
7, 14, 21, 28, 35, 42, 49, 56, 63, 70, . . .
We now list all integers in that list that have a remainder of 1 when divided by 3. They are
7, 28, 49, 70, . . .
All these terms differ by lcm[3, 7], or 21. Thus x ≡ 7 (mod 21).
However, we are guessing this is the solution. We write x ≡ 7 (mod 21) algebraically as
x = 21y + 7
where y is an integer. Since 21y + 7 ≡ 0 (mod 7) and 21y + 7 ≡ 1 (mod 3), we see that
12
Introduction to Modular Arithmetic CaptainFlint Page 13
23.3 Problem 3
23.3.1 Problem
Find all x such that
x≡3 (mod 4)
x≡2 (mod 7).
23.3.2 Solution
This problem would be hard to solve using the method in the previous problem. We need a systematic way
to solve this.
The first congruence tell us that x ≡ 3 (mod 4). We write this algebraically as
x = 4a + 3,
where a is an integer.
The second congruence tells us that x ≡ 2 (mod 7). We write this algebraically as
x = 7b + 2,
where b is an integer.
Thus, we have to system of equations:
x = 4a + 3 = 7b + 2.
We rearrange the equation as 4a + 1 = 7b, and mod 7 to get
4a + 1 ≡ 0 (mod 7).
We subtract 1 from both sides of this congruence, and get
4a ≡ −1 (mod 7) =⇒ 4a ≡ 6 (mod 7).
We multiply the congruence by the inverse of 4 (mod 7), which is 2. Thus, we have
4a ≡ 6 (mod 7)
2 × 4a ≡ 2 × 6 (mod 7)
8a ≡ 12 (mod 7)
8a ≡ 5 (mod 7)
1a ≡ 5 (mod 7)
a≡5 (mod 7).
We substitute a = 5 into the equation x = 4a + 3 = 7b + 2, and get x = 23. However this is not the only
solution, because we expect the solution to be a congruence.
Since
23 ≡ 3 (mod 4)
23 ≡ 2 (mod 7)
we subtract 23 from both sides of the congruences:
x − 23 ≡ 3 − 3 ≡ 0 (mod 4)
x − 23 ≡ 2 − 2 ≡ 0 (mod 7).
From this, we see that x − 23 is divisible by both 4 and 7, which are relatively prime, so x − 23 ≡ 0 (mod 28).
Thus, all values of x that satisfy the congruence are
x ≡ 23 (mod 28) .
13
Introduction to Modular Arithmetic CaptainFlint Page 14
24.1.2 Solution
We know that the solution to a system of two linear congruences is another congruence. If we take two
congruences and solve them, we get a single congruence. We can then combine this congruence with the
third remaining congruence, thus solving the whole system.
We begin by finding all x such that
x≡1 (mod 2)
x≡2 (mod 3).
Turning these into an algebraic form, we have
x = 2a + 1 = 3x + 2.
We rearrange to get 3x = 2a − 1, and take the modulo 3, and get
2a − 1 ≡ 0 (mod 3).
We solve for a in this congruence by adding 1 to both sides and multiplying by the inverse of 2 (mod 3),
which is 2. Thus, we have
2a − 1 ≡ 0 (mod 3)
2a ≡ 1 (mod 3)
2 × 2a ≡ 2 × 1 (mod 3)
4a ≡ 2 (mod 3)
1a ≡ 2 (mod 3)
a≡2 (mod 3).
Substituting a = 2 into x = 2a + 1 = 3x + 2 we have x = 5. Thus,
5≡1 (mod 2)
5≡2 (mod 3).
Subtracting 5 from the congruences, we have
x−5≡1−1≡0 (mod 2)
x−5≡2−2≡0 (mod 3).
Thus, x − 5 is a multiple of both 2 and 3, and because gcd(2, 3) = 1, we have x − 5 ≡ 0 (mod 6) =⇒ x ≡ 5
(mod 6).
Now we have the following system of congruences:
x≡5 (mod 6)
x≡0 (mod 5).
14
Introduction to Modular Arithmetic CaptainFlint Page 15
25.1 Problem
25.1.1 Problem
Find all integers x such that
x≡1 (mod 10),
x≡4 (mod 12).
25.1.2 Solution
We write the equations in an algebraic form, and get
x = 10a + 1 = 12b + 4.
We rearrange, and get
10a = 12b + 3.
However, one side of this equation is even, and the other is odd. Thus, this system has no solutions for x.
Combining earlier results, we see the following:
x ≡ 0 (mod 2),
⇒ x ≡ 0 (mod 10)
x ≡ 0 (mod 5)
x ≡ 1 (mod 3),
⇒ x ≡ 7 (mod 21)
x ≡ 0 (mod 7)
x ≡ 3 (mod 4),
⇒ x ≡ 23 (mod 28)
x ≡ 2 (mod 7)
x ≡ 1 (mod 10),
⇒ no solutions
x ≡ 4 (mod 12)
We can see that the GCD of the first 3 systems moduli are relatively prime, and the fourth are not. This
gives the following result:
15
Introduction to Modular Arithmetic CaptainFlint Page 16
26 Exercises
26.1 Exercise 1
Find all x such that
x≡3 (mod 4)
x≡5 (mod 9).
26.2 Exercise 2
Find all x such that
x−3≡4 (mod 2)
4x + 2 ≡ 0 (mod 5).
26.3 Exercise 3
Find the smallest possible positive value of n such that
n≡4 (mod 5)
n≡3 (mod 6)
n≡2 (mod 7).
Part XII
Problems
27 Problem 1: 2014 AMC8
The 7-digit numbers 74A52B1 and 326AB4C are each multiples of 3. What is the smallest possible value of
C?
16
Introduction to Modular Arithmetic CaptainFlint Page 17
0
1 1
2 2 2
3 4 4 3
4 7 8 7 4
5 11 15 15 11 5
Let f (n) denote the sum of the numbers in row n. What is the remainder when f (100) is divided by 100?
Part XIII
Solutions
In this part we have solutions to all the exercises in this manual.
35 Part II Exercises
35.1 Exercise 1
Remember that for integers a and b, a ≡ b (mod m) if and only if a − b is a multiple of m. 31 − 24 = 7, and
7 is not divisible by 9. Thus
31 6≡ 24 (mod 9).
35.2 Exercise 2
As before, we see if 45 − 15 is divisible by 3. Since 45 − 15 = 30, and 30 = 3 · 10,
45 ≡ 15 (mod 3).
17
Introduction to Modular Arithmetic CaptainFlint Page 18
2. 45 ≡ 0 (mod 9).
3. 23 ≡ 5 (mod 9).
5. 42 ≡ 6 (mod 9).
36.2 Exercise 2
1. 43 = 3 · 14 + 1.
2. 4 = 3 · 1 + 1.
3. 100 = 3 · 33 + 1.
4. 98 = 3 · 32 + 2.
5. 42 = 3 · 14 + 0.
6. −34 = 3 · (−12) + 2.
7. 1337 = 3 · 445 + 2.
36.3 Exercise 3
36.3.1 Solution 1
Since x ≡ y (mod a), we have x − y = am for some integer m. Since y ≡ z (mod a), we have y − z = an for
some integer n. Adding these equations, we get
(x − y) + (y − z) = am + an
x + (−y + y) − z = a(m + n)
x − z = a(m + n).
36.3.2 Solution 2
Since x ≡ y (mod a), x and y share the same column of a a-column counting grid since x and y have the
same residue. Similarly, y ≡ z (mod a), so y and c are also in the same column. This column has x, y, and
z, so x ≡ z (mod a).
18
Introduction to Modular Arithmetic CaptainFlint Page 19
37 Part IV Exercises
37.1 Exercise 1
54 + 42 ≡ 2 + 14 (mod 8)
6+2≡2+6 (mod 8)
0≡0 (mod 8).
37.2 Exercise 2
69 − 45 ≡ 18 − 15 (mod 3)
0−0≡0−0 (mod 3)
0≡0 (mod 3).
37.3 Exercise 3
The remainder when a + b + c is divided by 8 is the modulo-8 residue of a + b + c. We sum the modulo-8
residues of a, b, and c:
a + b + c ≡ 4 + 5 + 7 ≡ 16 ≡ 0 (mod 8).
38 Part V Exercises
38.1 Exercise 1
9 · 43 ≡ 8 · 98 (mod 23)
9 · 20 ≡ 8 · 6 (mod 23)
Thus, we have
38.2 Exercise 2
100! = 100 · 99! ≡ 0 · 99! ≡ 0 (mod 4).
38.3 Exercise 3
The product of three integers are congruent modulo 8 to the product of the modulo 8 residues of the three
integers. Multiplying, we have
1 · 4 · 7 ≡ 28 ≡ 4 (mod 8).
19
Introduction to Modular Arithmetic CaptainFlint Page 20
39 Part VI Exercises
39.1 Exercise 1
We add 1514 to both sides of the congruence, and get
From the law for modular exponentiation we have 24 ≡ 15 (mod 9) =⇒ 9 ≡ 0 (mod 9). Thus 2414 − 1514
is divisible by 9.
39.2 Exercise 2
Since 56 = 1 (mod 7), we split 56001 into as many powers of 56 as possible:
40.2 Exercise 2
Let n be an integer such that 0 ≤ n < 20. In order for n to have a residue modulo 20, gcd(n, 20) must be 1.
Listing all integers less than 20 that are relatively prime to 20, we have
41 Part IX Exercises
41.1 Exercise 1
We list the first few integers that are equivalent to 1 (mod 6). They are
41.2 Exercise 2
We turn this into the equation 19x + 21y = 1, and solve for x using the Euclidean Algorithm.
21 ÷ 19 has a quotient of 1 and a remainder of 2. 19 ÷ 2 has a quotient of 2 and a remainder of 1. This
gives us the equations
21 = 1 · 19 + 2
19 = 2 · 9 + 1.
Rearranging, we get
2 = 21 − 1 · 19
1 = 19 − 2 · 9.
20
Introduction to Modular Arithmetic CaptainFlint Page 21
Substituting, we get
1 = 19 − 2 · 9
= 19 − (21 − 1 · 19) · 9
= 19 − 21 · 9 + 19 · 9
= 10 · 19 − 9 · 21
Thus x = 10 .
41.3 Exercise 3
We turn this into the equation 17x + 23y = 1, and solve for x.
23 ÷ 17 has a quotient of 1 and a remainder of 6. 17 ÷ 6 has a quotient of 2 and a remainder of 5. 6 ÷ 5
has a quotient of 1 and a remainder of 1. This gives us the following equations:
23 = 1 · 17 + 6
17 = 2 · 6 + 5
6 = 1 · 5 + 1.
Isolating the remainders, we get
6 = 23 − 1 · 17
5 = 17 − 2 · 6
1 = 6 − 1 · 5.
We substitute, and work our way up the list. Finally, we get −4 · 17 + 3 · 23. Reducing modulo 23, we get
−4 · 17 ≡ 1 (mod 23) =⇒ 19 · 17 ≡ 1 (mod 23). Thus x = 19 .
42 Part X Exercises
42.1 Exercise 1
We multiply 23x ≡ 14 (mod 15) by the inverse of 23 (mod 15), which is 2. Multiplying, we get
23x ≡ 14 (mod 15)
2 · 23x ≡ 2 · 14 (mod 15)
1x ≡ 28 (mod 15)
x ≡ 28 (mod 15)
x ≡ 13 (mod 15).
42.2 Exercise 2
We subtract 234 from both sides, and simplify modulo 15.
23x + 234 ≡ 12 (mod 15)
23x + 234 − 234 ≡ 12 − 234 (mod 15)
23x ≡ −22 (mod 15)
23x ≡ 3 (mod 15).
We multiply by the inverse of 23 (mod 15), and get
x≡6 (mod 5) .
21
Introduction to Modular Arithmetic CaptainFlint Page 22
42.3 Exercise 3
We have ay − by = myn, where n is an integer. Diving by y, we get
a − b = mn =⇒ a ≡ b (mod m).
43 Part XI Exercises
43.1 Exercise 1
Converting into an algebraic form, we get
x = 4a + 3 = 9b + 5.
Rearranging, we get 4a = 9b + 2. Taking this equation modulo 4, we get 9b + 2 ≡ 0 (mod 4). We subtract 2
from both sides, and get
9b ≡ −2 (mod 4) =⇒ 9b ≡ 2 (mod 4).
Since 9 ≡ 1 (mod 4), we have b ≡ 2 (mod 4). We substitute b as 2 into x = 9b + 5, and solve for x:
x = 9 · 2 + 5 = 18 + 5 = 23.
Since
23 ≡ 3 (mod 4)
23 ≡ 5 (mod 9),
x − 23 ≡ 3 − 3 ≡ 0 (mod 4)
x − 23 ≡ 5 − 5 ≡ 0 (mod 9).
x ≡ 23 (mod 36) .
43.2 Exercise 3
We begin by isolating x in each of the congruences. In the first congruence, we add 3 to both sides, and
simplify. Thus, x ≡ 1 (mod 2).
In the second equation, we subtract 2 from both sides, and get 4x ≡ 3 (mod 5). Then we multiply by
the inverse of 4 modulo 5, which is 4. Thus, we have x ≡ 2 (mod 5).
Now we have system
x≡1 (mod 2)
x≡2 (mod 5).
x = 2a + 1 = 5b + 2.
We subtract 1 from both sides, and get 2a = 5b + 1. Taking the equation modulo 2, we get
22
Introduction to Modular Arithmetic CaptainFlint Page 23
x = 5 · 1 + 2 = 7.
x≡1 (mod 2)
x≡2 (mod 5).
We get
x−7≡0 (mod 2)
x−7≡0 (mod 5).
43.3 Exercise 3
We begin by solving the first two congruences, which will create another congruence as the solution. We
have
x = 5a + 4 = 6b + 3.
Subtracting 3 from all sides and reducing modulo 6, we have
7a = 30b + 7,
We multiply by 2−1 = 4, and get b ≡ 0 (mod 7). Substituting x = 0 into x = 7a + 2 = 30b + 9, we get x = 9.
Since gcd(7, 30) = 1, we have
x ≡ 9 (mod 210).
The smallest positive integer that satisfies this is x = 9 .
23
Introduction to Modular Arithmetic CaptainFlint Page 24
The n we want is therefore the last two digits of N , or N (mod 100). If instead we find N (mod 25), we
know that N (mod 100), what we are looking for, could be N (mod 25), N (mod 25)+25, N (mod 25)+50,
or N (mod 25) + 75. Only one of these numbers will be a multiple of four, and whichever one that is will
be the answer, because N (mod 100) has to be a multiple of 4.
If we divide N by 521 by taking out all the factors of 5 in N , we can write N as 2M
21 where
M = 1 · 2 · 3 · 4 · 1 · 6 · 7 · 8 · 9 · 2 · · · 89 · 18,
where every multiple of 5 is replaced by the number with all its factors of 5 removed. Specifically, every
number in the form 5n is replaced by n, and every number in the form 25n is replaced by n.
The number M can be grouped as follows:
24
Introduction to Modular Arithmetic CaptainFlint Page 25
Where the first line is composed of the numbers in 90! that aren’t multiples of five, the second line is the
multiples of five and not 25 after they have been divided by five, and the third line is multiples of 25 after
they have been divided by 25.
Using the identity at the beginning of the solution, we can reduce M to
Using the fact that 210 = 1024 ≡ −1 (mod 25) (or simply the fact that 221 = 2097152 if you have your
powers of 2 memorized), we can deduce that 221 ≡ 2 (mod 25). Therefore N = 2M 24
21 ≡ 2 (mod 25) = 12
(mod 25).
Solution from the AoPS Wiki
Finally, combining with the fact that N ≡ 0 (mod 4) yields n = 12 .
25
Introduction to Modular Arithmetic CaptainFlint Page 26
44.7.2 Solution 2
e have 32 = 9 ≡ 1 (mod 8). Hence for any k we have 32k ≡ 1k = 1 (mod 8), and then 32k+1 = 3·32k ≡ 3·1 = 3
(mod 8).
Therefore our sum gives the same remainder modulo 8 as 1 + 3 + 1 + 3 + 1 + · · · + 1 + 3. There are 2010
terms in the sum, hence there are 2010/2 = 1005 pairs 1 + 3, and thus the sum is
26