2 Modular Arithmetic
2 Modular Arithmetic
1 Introduction
The notion of congruence appeared very early in the history of humanity. This
is due to the fact that there are many cyclic events observed in nature. In
astronomy, nearly all objects are turning over themselves and around one an-
other, so that it is natural to divide time accordingly: a year corresponds to
one cycle of the earth around the sun, a month is derived from a cycle of the
moon, a day from the time it takes for the sun to rise or set in the same place.
We count days or months in a year, but when a year is over, the counting of
days or months starts over. Congruences and modular arithmetic will make the
process of “starting over” or “wrapping around” formal. On top of examples
that appear in nature, they have numerous applications in computer science, in
communications, and of course, in mathematics.
People are often aware of the concept of modular arithmetic without knowing
it. For example, the hours in a day are read modulo 12 (or 24 in certain
instances). If it is 9:00 P.M. and someone asks you what time it will be in 4
hours, you will likely say 1:00 A.M. This is because 9 + 3 = 12 and at 12 the
clock resets to 0. That is, one hour after 12:00 is 1:00. This is the essence of
modular arithmetic. If it is 7:00 and someone asks you what time it will be in
56 hours, you could notice that after 48 hours it will be 7:00, so it is the same
as asking what time it will be in 8 hours. Then taking 7 + 8 = 15 you realize
that this is 3 hours after 12:00, namely 3:00. This is exactly modular arithmetic
modulo 12.
Another example is the days of the week. Take Sunday as day 1, Monday as
day 2, Tuesday as day 3, Wednesday as day 4, Thursday as day 5, Friday as day
6 and Saturday as day 7. If it were Tuesday and you are asked what day it will
be in 10 days, you will say Friday. This is because adding 7 is essentially adding
0. Therefore, it is like adding 3 days to Tuesday (which is day 3), so that you
get day 6 which is Friday. This is modular arithmetic modulo 7. Likewise, the
months can be thought of as modular arithmetic modulo 12. For example, if it
is February and someone asks you what month it will be in 14 months, you will
say April, because in 12 months it will be February again so you are really just
adding 2.
For the musical reader, a scale would be yet another example. Say you are
playing in the key of C. Then the notes are written as C D E F G A B C. In
other words, your return to the first note on the eighth note. Similarly, if you are
playing in the key of D the notes are written as D E F] G A B C] D. In any key,
you have the notes very much arranged like the hours on a clock. Specifically,
if you move 24 hours ahead you are at the same time but in a different day.
Likewise, if you move 8 notes higher, you are on the same note but in a different
octave.
1
2 Computing modulo n ∈ N
We can now make these ideas rigorous. Let Z be the set of integers and let
n ∈ N+ = N \ {0}. We introduce the following relation on Z denoted by ≡
which equates two integers if their difference is a multiple of n.
Example 1 We have the following instances where two numbers are equivalent
under this relation.
1. We have that 20 ≡ 6 (mod 7) since 6 − 20 = −14 = −2 · 7, giving that 7
divides 6 − 20.
2. We have that 24 ≡ 112 (mod 11) since 112 − 24 = 88 = 8 · 11, giving that
11 divides 112 − 24.
3. We have that 99 ≡ 13 (mod 43) since 13 − 99 = −86 = −2 · 43, giving
that 43 divides 13 − 99.
2. It is not too difficult to check that 25 ≡ 2 (mod 5). Now can you check
37 ≡ 3 (mod 7)? And 1219 ≡ 12 (mod 19)? The answer will be given by
the so-called “Fermat’s Little Theorem”.
The modulo relation defined above is a special kind of relation that was
discussed in Chapter ??. Namely, it is an equivalence relation. We shall prove
this now. Throughout, we use the fact that if n divides b − a then b − a = kn
for some k ∈ Z.
2
1. (Reflexive Property): Let a ∈ Z. Then a − a = 0 · n. This gives that
a ≡ a (mod n) and the relation is reflexive.
2. (Symmetric Property): If a ≡ b, then b − a = kn which gives that
a − b = (−k)n. Therefore, b ≡ a (mod n).
3. (Transitive Property): If a ≡ b and b ≡ c, then b − a = kn and
c − b = gn. Then c − a = b − a + c − b = kn + gn = (k + g)n which gives
that a ≡ c (mod n).
Therefore, we have that this is an equivalence relation.
Note that not only is the union of the sets (a + nZ) equal to the integers,
but also that they are disjoint – that is there is no element in the intersection
of any two distinct sets. Therefore, these sets form a partition of the integers.
3
... −12 −7 ... −11 −6
−2 3 8 −1 4 9
13 18 . . . 14 19 . . .
We need to give a name to each of the boxes. It seems natural to give them
the name that is the number in the center of each box. Namely, if a number
can be written as 5k + s, 0 ≤ s < 5, (that is the remainder of the number
when divided by 5 is s) then we can associate the number with s. Since it is an
equivalence relation, it makes sense to call these boxes:
0, 1, 2, 3, 4.
We note that
Being a partition of Z, the intersection of any two distinct sets of the form
a + nZ and b + ZZn is empty. These subsets are the equivalence classes, there
are n of them.
From this point on, when describing the elements of the set Zn we shall drop
the notation nZ. We write {0, 1, . . . , n − 1} for the set Zn when no confusion
will arise. Coming back to our example, for n = 2 we have two classes: the odd
integers and the even integers. In other words Z2 = {0, 1}.
We note that we can really take any element in a + nZ as its representative,
but we shall always take the smallest non-negative element in a + nZ to be its
representative. This set is the set of elements which are equivalent to a modulo
n and it is called the remainder class of a modulo n or congruence class of a
modulo n.
Proof:
4
1. Let a + nZ = b + nZ. We know that a ∈ a since a ≡ a (mod n). Since
a + nZ = b + nZ, we have a ∈ b + nZ, which gives that a ≡ b (mod n).
For the converse we have a ≡ b (mod n). Take x ∈ a + nZ. This means
that x ≡ a (mod n). By the transitive property, we have x ≡ b (mod n)
which means that x ∈ b + nZ. Hence, a + nZ ⊂ b + nZ. Similarly take an
element y ∈ b + nZ. This means that y ≡ b (mod n). By the transitive
property we have y ≡ a (mod n) which means that y ∈ a + nZ. Hence
b + nZ ⊂ a + nZ. Finally we have that a + nZ = b + nZ.
From this point on, we shall dispense with the notation a + nZ for elements
in Zn , and we shall simply write the elements as the set {0, 1, 2, . . . , n − 1}.
Moreover, we shall indicate multiplication in the standard ways, in other words
ab = a(b) = a · b. We only use the a · b notation when we want to stress that
the operation is multiplication.
Let us mention another point of view on congruence classes modulo n ∈ N.
Let ρn : Z → {0, 1, . . . , n − 1} be the function such that ρn (a) is the remainder
of a while divided by n. The different classes modulo n are given by the different
pre-images of ρn . In other words, we can write the different classes of congruence
modulo n as the equivalence class of a, that is {i | ρn (i) = a}. It is easy to see
that what we have defined is the following.
Let n ∈ N, a ∈ Z, then
ρn (a) = a (mod n),
where a is the smallest non-negative representative of that class in Zn .
Alternatively, we can consider ρn (a) to be the remainder when a is divided
by n.
5
1. ρ7 (23) = 2.
2. ρ11 (58) = 3.
3. ρ9 (25) = 7.
4. ρ7 (74) = 4.
5. ρ12 (116) = 8.
6. ρ5 (44) = 4.
7. ρ10 (55) = 5.
8. ρ21 (48) = 6.
9. ρ2 (131) = 1.
1. ρ−1
5 (0) = {. . . , −20, −15, −10, −5, 0, 5, 10, 15, 20, . . . }.
2. ρ−1
4 (1) = {. . . , −23, −19, −15, −11, −7, −3, 1, 5, 9, 13, 17, 21, . . . }.
3. ρ−1
7 (5) = {. . . , −37, −30, −23, −16, −9, −2, 5, 12, 19, 26, 33, 40, . . . }.
4. ρ−1
9 (8) = {. . . , −46, −37, −28, −19, −10, −1, 8, 17, 26, 35, 44, 53, . . . }.
For a, b ∈ Z:
and
a (mod n) · b (mod n) ≡ ab (mod n).
These definitions lead to a question: are they well defined? In other words
are these definitions independent of the elements used to represent the classes?
This means if a ≡ a0 (mod n) and b ≡ b0 (mod n), do we have a + b ≡ a0 + b0
(mod n) and ab ≡ a0 b0 (mod n)? We can now prove this result.
Theorem 2 Addition and multiplication modulo n are well defined. That is, if
a ≡ a0 (mod n) and b ≡ b0 (mod n) then
a+b ≡ a0 + b0 (mod n)
and
ab ≡ a0 b0 (mod n).
6
Proof: If a ≡ a0 (mod n), then a = kn + s and a0 = k 0 n + s for some
integers k and k 0 . If b ≡ b0 (mod n), then b = gn + t and b0 = g 0 n + t for some
integers g and g 0 .
Then a + b = kn + s + gn + t = (k + g)n + s + t which gives a + b ≡ a0 + b0
(mod n).
For multiplication, we have ab = (kn + s)(gn + t) = kgnn + sgn + ktn + st =
(kgn + sg + kt)n + st which gives ab ≡ a0 b0 (mod n).
Example 8 We illustrate this theorem with the addition and multiplication ta-
bles modulo 2 and modulo 3.
+ 0 1 · 0 1
0 0 1 0 0 0
1 1 0 1 0 1
+ 0 1 2 · 0 1 2
0 0 1 2 0 0 0 0
1 1 2 0 1 0 1 2
2 2 0 1 2 0 2 1
+ 0 1 2 3 · 0 1 2 3
0 0 1 2 3 0 0 0 0 0
1 1 2 3 0 1 0 1 2 3
2 2 3 0 1 2 0 2 0 2
3 3 0 1 2 3 0 3 2 1
We note that there are significant differences between these and the previous
two. For example, look at the row for multiplication by 2. We have 2(2) ≡ 0
(mod 4). In the previous examples there were no instances where two non-zero
numbers were multiplied to get 0. Moreover, we have 2(3) ≡ 2(1) (mod 4). In
the previous examples, each equation of the form ax ≡ b (mod n) had a unique
solution, whereas here 2x ≡ 2 (mod 4) has two solutions. This is quite different
from arithmetic in the integers, rational or reals.
(a + b) + c (mod n) ≡ a + (b + c) (mod n)
and
(a · b) · c (mod n) ≡ a · (b · c) (mod n).
and
a · 1 ≡ a (mod n).
7
3. (Additive inverses) For every a ∈ Zn there exists b ∈ Zn such that a + b ≡
b + a ≡ 0 (mod n).
Proof:
1. For any a, b, c ∈ Z we have (a+b)+c = a+(b+c) and (ab)c = a(bc). Then
simply take each side (mod n) to get (a + b) + c (mod n) ≡ a + (b + c)
(mod n) and (a · b) · c (mod n) ≡ a(b · c) (mod n).
+ 0 1 2 3 4 5 · 0 1 2 3 4 5
0 0 1 2 3 4 5 0 0 0 0 0 0 0
1 1 2 3 4 5 0 1 0 1 2 3 4 5
2 2 3 4 5 0 1 2 0 2 4 0 2 4
3 3 4 5 0 1 2 3 0 3 0 3 0 3
4 4 5 0 1 2 3 4 0 4 2 0 1 2
5 5 0 1 2 3 4 5 0 5 4 3 2 1
We can easily verify all of the properties given in Lemma 1. We can see that
both operations are commutative since both tables are symmetric. Moreover,
we note that Z6 is much more like Z4 than it is like Z2 or Z3 . Namely, we
have 2(3) = 3(2) ≡ 0 (mod 6). That is, there exists non-zero elements that can
multiply together to get 0.
8
Since we can multiple these elements we can also doing other arithmetic
operations associated with multiplication. For example, we can take an element
a and square it, since a2 = a(a). This is actually a very important operation in
modular arithmetic and has numerous uses. In the next examples, we can see
how different this operation is in modular arithmetic than it is in the integers.
x 0 1 2 3 4 5 6 7
2
x (mod 8) 0 1 4 1 0 1 4 1
We note first of all that there are 4 solutions to the equation x2 = 1, namely
1, 3, 5, and 7. We also note that 42 = 0, so there is a non-zero element that
when squared is 0. These types of things do not occur in the integers. To further
illustrate the differences with Z, consider the cubes in Z8 . We can compute this
table simply by multiplying the elements in the table for x2 by the element x.
x 0 1 2 3 4 5 6 7
x3 (mod 8) 0 1 0 3 0 5 0 7
Notice that there are 5 solutions to x3 = x which cannot happen in the integers,
since the polynomial x3 −x = 0 can have at most 3 solutions in the real numbers.
Moreover, we have 3 non-zero elements that satisfy x3 = 0, this also does not
happen in the integers.
If we take it further, to x4 , it looks even more unusual.
x 0 1 2 3 4 5 6 7
x4 (mod 8) 0 1 0 1 0 1 0 1
Example 12 We contrast the previous example with the squares modulo a prime
number, for example 11.
x 0 1 2 3 4 5 6 7 8 9 10
x2 (mod 11) 0 1 4 9 5 3 3 5 9 4 1
Here the behavior is much more similar to the way squares behave in the integers.
We note that there are no non-zero elements whose square is 0 and no equation
of the form x2 ≡ a (mod 11) has more than 2 solutions. We note as well, that
precisely half of the non-zero elements are squares, namely 1, 3, 4, 5, and 9.
9
Example 13 We can take a look at another set of squares modulo a prime.
Consider the prime 5.
x 0 1 2 3 4
x2 (mod 5) 0 1 4 4 1
One of the most interesting aspects here is that 4 ≡ −1 (mod 5). This means
that in Z5 , the equation x2 + 1 = 0 has two solutions. In other words, there
are x such that x2 = −1, or in the notation that we have been using x2 ≡ −1
(mod 5). This means that −1 is a square, which certainly does not happen in
the integers or the real numbers. This algebraic fact can be exploited in many
ways in number theory and abstract algebra.
4. 36 (mod 6).
5. 113 (mod 8).
6. 233 (mod 21).
10
9. 36 (mod 7).
10. 424 (mod 8).
1. 322 .
2. 4162 .
3. 510598 .
4. 65679 .
5. 11321 .
6. 25! + 7351 .
7. 402! + 835 .
Exercise 9 Find all solutions to x3 ≡ x (mod 16) by examining all the possi-
bilities.
B Exercises
11
Exercise 17 Determine how many times 3 appears in the multiplication table
for Z7 . Determine how many times 3 appears in the multiplication table for Zp ,
when p > 3 is a prime.
Exercise 18 Let ac ≡ bc (mod n) and gcd(c, n) = 1. Show that a ≡ b (mod n).
Exercise 19 Let ab ≡ cd (mod n), b ≡ d (mod n) and gcd(b, n) = 1. Prove
that a ≡ c (mod n).
C Exercises
Exercise 20 Write a computer program to do modular arithmetic modulo n,
for a chosen n, without using any built in modulo functions. Begin by writing a
function that takes a number modulo n, then a function that performs addition
and finally one that performs multiplication.
Exercise 21 Determine how many times 0 appears in the multiplication table
for Zn . Do this by taking several examples for small n. Then try and develop
a conjecture (You can split up the conjecture for different forms of n. You
might try numbers of the form pe and then for numbers of the form ab where
gcd(a, b) = 1.) Prove whichever of these conjectures you can.
12
We note that there is no b with 2b ≡ 1 (mod 6). Therefore, 2 is not invertible in
Z6 . However, 1(1) ≡ 1 (mod 6) and 5(5) ≡ 1 (mod 6) are invertible elements.
It is easy to verify that 3 and 4 are also not invertible. Therefore, in Z6 , the
only invertible elements are 1 and 5.
ab = ac
bab = bac
1b = 1c
b = c.
The intuitive way to think about the previous theorem is to say that both 1
and −1 are invertible elements in Zn .
We can now define one of the unusual things that happened in the previous
examples.
Example 16 Consider the element 8 in Z12 . Here 8(3) ≡ 0 (mod 12). There-
fore, both 8 and 3 are zero divisors in Z12 . Note also that 4(3) ≡ 0 (mod 12)
and so 4 is also a zero divisor. We note that both 4(3) and 8(3) are equivalent
to 0 (mod 12). This shows that, given a = 3, there is not a unique zero divisor
b in the above definition.
13
Example 17 We can look at all the non-zero elements in Z12 .
element invertible zero divisor
1 1(1) ≡ 1 (mod 12) No
2 No 2(6) ≡ 0 (mod 12)
3 No 3(4) ≡ 0 (mod 12)
4 No 4(3) ≡ 0 (mod 12)
5 5(5) ≡ 1 (mod 12) No
6 No 6(2) ≡ 0 (mod 12)
7 7(7) ≡ 1 (mod 12) No
8 No 8(3) ≡ 0 (mod 12)
9 No 9(4) ≡ 0 (mod 12)
10 No 10(6) ≡ 0 (mod 12)
11 11(11) ≡ 1 (mod 12) No
We note a few interesting things in this table. The first is that no element is
both invertible and a zero divisor. We shall prove this in the next few theorems.
Secondly the equation x2 ≡ 1 (mod 12) has 4 solutions, namely 1, 5, 7, and 11.
Notice also that the equation 4x ≡ 0 (mod 12) has 4 solutions, namely 0, 3, 6,
and 9. Later in the chapter, we shall determine precisely how many solutions
every linear equation has.
We continue with an easy result which shows that being invertible prohibits
an element from being a zero divisor, as we have seen in the previous example.
Theorem 5 If an element in Zn is invertible then it is not a zero divisor.
The next result shows how to use the Euclidean algorithm to not only prove
that an element is invertible but also to find its inverse.
Theorem 6 If gcd(a, n) = 1 then a is invertible in Zn .
Example 18 We can find the inverse of 5 in Z12 . We begin by taking the Eu-
clidean Algorithm:
12 5 2 1 0
This gives the following:
5 − 2(2) = 1
5 − 2(12 − 2(5)) = 1
5(5) − 2(12) = 1.
Then reading this equation modulo 12 gives 5(5) ≡ 1 (mod 12). Therefore, 5 is
the multiplicative inverse of 5 in Z12 .
14
Since it is fairly easy to find the inverse of 5 in Z12 by guessing, our next
example will show the technique in a more difficult situation.
9−8 = 1
9 − (17 − 9) = 1
2(9) − 17 = 1
2(43 − 2(17)) − 17 = 1
2(43) − 5(17) = 1.
9 − 2(4) = 1
9 − 2(13 − 9) = 1
3(9) − 2(13) = 1
3(100 − 7(13)) − 2(13) = 1
3(100) − 23(13) = 1.
We note that −23 ≡ 77 (mod 100). Therefore, reading the equation modulo 100
we have 77(13) ≡ 1 (mod 100). This gives that the multiplicative inverse of 13
is 77 in Z100 . We can verify this by noting that 77(13) = 1001 ≡ 1 (mod 100).
We can now give a theorem which determines when a number is a zero divisor
in Zn .
15
Proof: Let d = gcd(a, n) > 1. Then a = da0 and n = dn0 , for some
a0 , n0 ∈ Z. Note that n0 6≡ 0 (mod n). Then an0 = da0 n0 = a0 dn0 = a0 n ≡ 0
(mod n). Therefore, a is a zero divisor.
Example 22 Consider the element 22 in Z40 . We have that the gcd(22, 40) = 2.
Then 22( 40
2 ) = 22(20) = 440 ≡ 0 (mod 40).
Example 23 Consider the element 10 in Z55 . We have that the gcd(10, 55) = 5.
Then 10( 55
5 ) = 10(11) = 110 ≡ 0 (mod 55).
The invertible elements of Zn are called its units and we will denote the set
of units by U (Zn ). In modular arithmetic, the set of units of Zn is also very
often denoted by Z∗n . Let us extract from the above theorem the most important
of these characterizations:
U (Zn ) = {a ∈ Zn | gcd(a, n) = 1}
16
Theorem 8 If a is a nilpotent or idempotent element that is neither 0 nor 1,
then a is a zero-divisor.
The next theorem is sometimes known as Wilson’s theorem (at least the
third part of it is).
Proof:
17
2. Find all invertible elements (mod 18).
3. Find all invertible elements (mod 11).
4. Find all invertible elements (mod 8).
5. Find all invertible elements (mod 16).
Exercise 25 For the given element a, find the smallest non-zero element b such
that ab ≡ 0 (mod n).
1. 6 in Z32 .
2. 14 in Z52 .
3. 15 in Z50 .
4. 18 in Z27 .
5. 8 in Z520 .
6. 22 in Z77 .
7. 26 in Z39 .
8. 100 in Z844 .
9. 123 in Z777 .
18
10. 432 in Z900 .
Exercise 26 Find all idempotent and nilpotent elements in Z8 , Z10 and Z16 .
B Exercises
Exercise 27 Prove that a number a in Z2k is a unit if and only if a is odd.
Exercise 28 Show that if an element a, a 6= 0, is not a zero divisor in Zn then
it is invertible.
Exercise 29 Prove that if a2 ≡ 1 (mod n) a 6= ±1, then a + 1 is a zero divisor
in Zn .
Exercise 30 Prove that every non-zero element in Zn is either a zero divisor
or a unit. Show that this is not the case in Z.
C Exercises
Exercise 31 Write a program to find the multiplicative inverse of an element
a ∈ Zn , when Igcd(a, n) = 1, using the Euclidean algorithm.
Example 25 Consider the equation 3x ≡ 7 (mod 11). Here 3 and 11 are rela-
tively prime. The number 4 is the multiplicative inverse of 3, that is 3(4) ≡ 1
(mod 11). Then we have:
3x ≡ 7 (mod 11)
4(3)x ≡ 4(7) (mod 11)
x ≡ 6 (mod 11).
19
Example 26 Consider the equation 5x ≡ 2 (mod 16). Here 5 and 16 are rela-
tively prime. The number 13 is the multiplicative inverse of 5, that is 5(13) ≡ 1
(mod 16). Then we have:
5x ≡ 2 (mod 16)
13(3)x ≡ 13(2) (mod 16)
x ≡ 10 (mod 16).
Example 27 Consider the equation 11x ≡ 17 (mod 23). Here 11 and 23 are
relatively prime. The number 21 is the multiplicative inverse of 11, that is
21(11) ≡ 1 (mod 23). Then we have:
The next lemma will examine the case when no solution exists.
b = ax + kn
b = da0 x + dkn0
b = d(a0 x + kn0 ).
This implies that d must divide b if there is a solution. Therefore, if d does not
divide b then there is not solution.
Example 28 Consider the equation 3x ≡ 5 (mod 9). Here, the greatest com-
mon divisor of 3 and 9 is 3, but 3 does not divide 5. This means that if
5 − 3x = 9k then 5 = 3(x + 3k). This is not possible since 3 does not di-
vide 3. To illustrate this point consider the possible elements modulo 9 and their
multiple by 3.
x (mod 9) 0 1 2 3 4 5 6 7 8
3x (mod 9) 0 3 6 0 3 6 0 3 6
The only results are 0, 3 and 6 which are the numbers in Z9 that are multiple of
3.
20
Lemma 4 The equation ax ≡ b (mod n) has d solutions if gcd(a, n) = d and
d does divide b.
b = ax + kn
b = da0 x + dkn0
db0 = d(a0 x + kn0 )
0
b = (a0 x + kn0 )
b0 − a0 x = kn0 .
All we have to do now is to show that these are all solutions to the original
equation. Recall that a0 c = b0 + hn0 for some h ∈ Z since c was a solution to
the earlier modular equation.
Example 30 Consider the modular equation 15x − 3 ≡ 12 (mod 35). The first
thing we do is to add 3 to both sides to get 15x ≡ 15 (mod 35). Our first thought
when looking at this equation is to realize that x = 1 is a solution. We may be
tempted to stop there, but we would be wrong as there are other solutions to
this equation. We have that gcd(15, 35) = 5 and 5 divides 15 so we should have
21
5 solutions. We reduce this equation by dividing by 5 to get: 3x ≡ 3 (mod 7)
which has a unique solution of 1. Then the solutions are 1, 8, 15, 22 and 29. We
have
We note that when d = 1 this theorem gives that there is a unique solution.
If we take the equation modulo b on both sides of the equation, the Diophan-
tine equation above can be written as ax ≡ c (mod b). We know from previous
results that this equation has solutions if gcd(a, b) | c.
22
Proof: If (x0 , y0 ) is a solution for the Diophantine equation ax + by = c,
then we can write ax0 + by0 = c. Subtracting both equations we get a(x − x0 ) +
b(y − y0 ) = 0. By taking modulo b, we get a(x − x0 ) ≡ 0 (mod b). This gives
that b | a(x − x0 ). As we are given that gcd(a, b) = 1, we have that b | x − x0 .
So x − x0 = bk, k ∈ Z, which means that x = x0 + bk.
On the other hand, a(x−x0 )+b(y−y0 ) = 0 means that ax−ax0 +by−by0 = 0.
In the last equation, writing x0 + bk instead of x, we get a(x0 + bk) − ax0 +
by − by0 = 0 which means that ax0 + abk − ax0 + by − by0 = 0. We have
abk + by − by0 = 0 and so by = by0 − abk. Dividing both sides by b 6= 0, we have
that y = y0 − ak.
5 = 3·1+2
3 = 2·1+1
2 = 1 · 2 + 0.
We have
1 = 3 + 2 · (−1)
= 3 + (5 + 3 · (−1)) · (−1)
= 5 · (−1) + 3 · 2.
5 · (−23) + 3 · 2 · 23 = 1 · 23
and then
5 · (−23) + 3 · 46 = 23.
Hence x0 = −23 and y0 = 46. We write all the solutions as x = x0 + bk =
−23 + 3k and y = y0 − ak = 46 − 5k, k ∈ Z.
We understand from the above example that the solution set is infinite. For
k = 0, we have x = −23 and y = 46 and so (x, y) = (−23, 46). For k = 1, we
have (x, y) = (−20, 41). For k = 2, we have (x, y) = (−17, 36) and so on. It
is obvious that if we apply one of the solutions, say (x, y) = (−23, 46), it will
satisfy the Diophantine equation as 5 · (−23) + 3 · 46 = 23.
Example 33 Consider the equation 21x + 12y = 66. We have gcd(21, 12) = 3
and 3 divides 66 so this equation does have a solution. We simply write the
equation as 7x + 4y = 22 by dividing both sides by 3. For the last equation,
gcd(7, 4) = 1 and 1 | 22. We apply the Euclidean Algorithm:
7 4 3 1 0
23
The computations are as follows:
7 = 4·1+3
4 = 3·1+1
3 = 1 · 3 + 0.
We have
1 = 4 + 3 · (−1)
= 4 + (7 + 4 · (−1)) · (−1)
= 7 · (−1) + 4 · 2.
Multiplying both sides of the last equation by 66, we get
1 · 66 = 7 · (−1) · (3 · (−22)) + 4 · 2 · 3 · 22
and then
66 = 21 · 22 + 12 · 44.
Hence, x0 = −22 and y0 = 44. We write all the solutions as x = x0 + bk =
−22 + 12k and y = y0 − ak = 44 − 21k, k ∈ Z.
Example 34 Consider the equation 119x + 95y = 143. We have gcd(119, 95) =
1 and 1 divides 143 so the equation does have a solution. We apply the Euclidean
Algorithm:
119 95 24 23 1 0
The computations are as follows:
119 = 95 · 1 + 24
95 = 24 · 3 + 23
24 = 23 · 1 + 1
23 = 1 · 23 + 0.
We have
1 = 24 + 23 · (−1)
= 24 + (95 + 24 · (−3)) · (−1)
= 24 · 4 + 95 · (−1)
= (119 + 95 · (−1)) · 4 + 95 · (−1)
= 119 · 4 + 95 · (−5).
Multiplying both sides of the last equation by 143, we get
119 · 4 · 143 + 95 · (−5) · 143 = 1 · 143
and then
119 · 572 + 95 · (−715) = 143.
Hence x0 = 572 and y0 = −715. We write all the solutions as x = x0 + bk =
572 + 95k and y = y0 − ak = −715 − 119k, k ∈ Z.
Example 35 Consider the equation 119x+133y = 143. We have gcd(119, 133) =
7 but 7 does not divide 143 as 143 = 11 · 13. So the equation does not have a
solution.
24
Exercises for Section 4
A Exercises
2. 5x ≡ 9 (mod 11).
3. 4x ≡ 5 (mod 9).
4. 2x ≡ 5 (mod 13).
5. 7x ≡ 12 (mod 15).
2. 3x ≡ 6 (mod 9).
3. 2x ≡ 5 (mod 10).
4. 8x ≡ 12 (mod 20).
5. 9x ≡ 3 (mod 12).
6. 5x ≡ 9 (mod 15).
7. 6x ≡ 12 (mod 18).
8. 10x ≡ 5 (mod 15).
2. 4x + 5 ≡ 11 (mod 13).
3. 9x − 4 ≡ 2 (mod 10).
4. 2x + 8 ≡ 10 (mod 17).
5. 11x − 4 ≡ 2 (mod 24).
25
Exercise 35 Solve the following equations:
1. 2x + 5y = 83.
2. 17x + 83y = 135.
3. 20x + 38y = 56.
4. 35x + 20y − 84 = 0.
5. 20x − 33y = 9.
6. 105x + 5y − 10 = 0.
7. 41x − 12y + 7 = 0.
8. 405x + 804y = 3.
9. 286x + 230y − 6531 = 0.
B Exercises
Exercise 36 Prove that x2 ≡ a (mod p) has either no solutions or 2 solutions
when p is a prime and a is not 0.
Exercise 37 Find an n where x2 ≡ −1 (mod n) has a solution and an n where
x2 ≡ −1 (mod n) has no solution.
C Exercises
Exercise 38 Write a computer program to find all solutions to x2 ≡ 1 (mod n).
Run this for various n and determine some conjectures about the number of so-
lutions to this equation for various n.
Exercise 39 Develop a conjecture for when x2 ≡ −1 (mod n) has a solution
and prove it.
26
They would have given an answer of 23 as the smallest such number. We would
specify all numbers satisfying the equations as x ≡ 23 (mod 30).
Example 36 We shall begin with an example. Assume we wanted to solve the
system of equations:
x ≡ 2 (mod 4)
x ≡ 3 (mod 7).
We can see that the number 6 satisfies the first equation but does not satisfy
the second, whereas the number 3 satisfies the second but not the first.
We shall show how to solve this system of equations. Any number satisfying
the first equation must be of the form 4k + 2 for some k ∈ Z. Then we put this
in the second equation to get 4k + 2 ≡ 3 (mod 7). Then we get 4k ≡ 1 (mod 7).
At this point we realize that gcd(4, 7) = 1 so we know that there is a unique
solution to this equation. We see that this solution is k ≡ 2 (mod 7). This
means that k is of the form k = 7g + 2. Then we apply this to the first equation
to get
x = 4k + 2 = 4(7g + 2) + 2 = 10 + 28g.
This means any number of this form will be a solution to both equations. The
solution can then be written as x ≡ 10 (mod 28). Consider the number 66 which
is 10 (mod 28). We have 66 (mod 4) = 2 and 66 (mod 7) = 3. The key to
solving this system was the fact that 4 and 7 were relatively prime. If they were
not there would not have been a unique solution to 4k ≡ 1 (mod 7).
We can now state the first theorem.
Theorem 12 If gcd(n, m) = 1, then there is a unique solution modulo nm to
the system:
x ≡ a (mod n)
x ≡ b (mod m).
Proof: For x to satisfy the first modular equation, we have that x must
be of the form x = kn + a for some k ∈ Z. Then we have:
kn + a ≡ b (mod m)
kn ≡ b−a (mod m).
Since gcd(n, m) = 1, there is a unique solution for k (mod m). Call this solution
α. That is αn ≡ b − a (mod m). This means that k is of the form α + gm for
some g ∈ Z. Then we have
x = kn + a
x = (α + gm)n + a
x = αn + gma + gmn
x ≡ αn + gma (mod mn).
27
Example 37 We shall solve the following system:
x ≡ 5 (mod 7)
x ≡ 4 (mod 8).
x ≡ 3 (mod 11)
x ≡ 7 (mod 19).
Let x = 11k +3. Then 11k +3 ≡ 7 (mod 19) gives 11k ≡ 4 (mod 19). Since this
equation is not obvious by inspection we shall describe the solution completely.
Apply the Euclidean algorithm to 19 and 11 and get
19 11 8 3 2 1 0
Then we have
3−2 = 1
3 − (8 − (2)3) = 1
3(3) − 8 = 1
3(11 − 8) − 8 = 1
3(11) − 4(8) = 1
3(11) − 4(19 − 11) = 1
7(11) − 4(19) = 1.
This gives 7(11) ≡ 1 (mod 19). Then we have k ≡ 7(4) ≡ 9 (mod 19) and
k = 19g + 9. Finally,
Example 39 We shall solve the following system with some thought rather than
blindly applying the algorithm. Examine the following system:
x ≡ 25 (mod 27)
x ≡ 1599 (mod 1601).
At first glance, it seems like there will be a lot of computation to solve this
system. But a little bit of thinking makes us realize that we can rewrite the
system as follows:
x ≡ −2 (mod 27)
x ≡ −2 (mod 1601).
28
We can easily generalize this theorem to the main Chinese Remainder The-
orem which handles an arbitrary number of modular congruences.
Theorem 13 (Chinese Remainder Theorem) Let n1 , n2 , . . . , ns be natural
numbers with gcd(ni , nj ) = 1, if i 6= j. Then there is a unique solution modulo
n1 n2 n3 · · · ns to the system:
x ≡ a1 (mod n1 )
x ≡ a2 (mod n2 )
x ≡ a3 (mod n3 )
..
.
x ≡ as (mod ns ).
This system has one fewer modular equation than the previous. We apply this
inductively until we have one remaining modular equation modulo n1 n2 n3 · · · ns .
Solving the first two modular equations we get x ≡ 4 (mod 15). Then we solve
the following system:
x ≡ 4 (mod 15)
x ≡ 5 (mod 7).
29
Example 41 Consider the following system:
x ≡ 9 (mod 10)
x ≡ 12 (mod 13)
x ≡ 16 (mod 17).
At first glance it may seem like it will require a great amount of computations
to solve. However, closer inspection allows us to see that we can write the three
equations as follows:
x ≡ −1 (mod 10)
x ≡ −1 (mod 13)
x ≡ −1 (mod 17).
We shall now take a look at a system where we cannot apply the Chinese
Remainder Theorem. Consider the following system of modular equations:
x ≡ 2 (mod 4)
x ≡ 4 (mod 6).
We note that 4 and 6 are not relatively prime. Here, both 10 and 22 are solutions
modulo 24 to the system.
Next consider the following system of modular equations:
x ≡ 3 (mod 4)
x ≡ 4 (mod 6).
The numbers that are 3 (mod 4) and less than 24 are 3, 7, 11, 15, 19, 23. None of
these numbers are 4 (mod 6). Therefore, in this situation there is no solution.
For both of these cases, the problem lies in the fact that gcd(4, 6) = 2 6= 1.
Consider also the following system:
x ≡ 0 (mod 2)
x ≡ 1 (mod 4).
All numbers satisfying the first modular equation must be even. However, all
numbers satisfying the second modular equation must be odd. Therefore, of
course, there are no solutions to this system of modular equations. It should be
clear now that it is absolutely necessary for the moduli to be relatively prime
to apply the Chinese Remainder Theorem.
We shall now take another look at the Chinese Remainder Theorem and
present a technique for solving systems of modular equations.
30
Let us present the system we want to solve. Given s ∈ N, n1 , . . . , ns ∈ N,
a1 , . . . , as ∈ Z and assuming that for 1 ≤ i 6= j ≤ s, ni is relatively prime with
nj . We want to solve the system
x ≡ ai (mod ni ).
That is we want to find all the integers x satisfying all of these equations.
To avoid confusion created by indexes, we will just treat the case of a system
with three equations.
x ≡ a1 (mod n1 )
x ≡ a2 (mod n2 )
x ≡ a3 (mod n3 )
n2 n3 u1 + n1 v1 = 1.
n 1 n 3 u 2 + n 2 v2 = 1
n 1 n 2 u 3 + n 3 v3 = 1.
Then x2 = n1 n3 u2 and x3 = n1 n2 u3 .
x ≡ a1 x1 + a2 x2 + a3 x3 (n1 n2 n3 ) ,
x≡r (mod n1 n2 n3 )
x ≡ 1 (mod 7)
x ≡ 4 (mod 9)
x ≡ 3 (mod 5).
31
First step. The particular equations and their solutions are as follows. Note
that we are solving these using the Euclidean algorithm as we have done so many
times before.
45 u1 + 7 v1 = 1; sol. 45 · (−2) + 7 · 13 = 1. Hence x1 = −90.
35 u2 + 9 v2 = 1; sol. 35 · (−1) + 9 · 4 = 1. Hence x2 = −35.
63 u3 + 5 v3 = 1; sol. 63 · 2 − 5 · 25 = 1 Hence x3 = 126.
We note that once we have solved the first step, we have easy solutions for
any ai that we choose.
We shall now show another application of the Chinese Remainder Theorem
using square roots. We begin with an example. The number 4 is a square in
Z5 , specifically, 22 ≡ 32 ≡ 4 (mod 5). It is also a square in Z7 , 22 ≡ 52 ≡ 4
(mod 7). In Z5 , we can say that the square roots of 4 are 2 and 3 and in Z7 , we
can say that the square roots of 4 are 2 and 5.
Apply the Chinese Remainder Theorem to the following 4 systems of mod-
ular equations:
x ≡ 2 (mod 5) x ≡ 2 (mod 5)
x ≡ 2 (mod 7) x ≡ 5 (mod 7)
x ≡ 3 (mod 5) x ≡ 3 (mod 5)
x ≡ 2 (mod 7) x ≡ 5 (mod 7)
The solution to the first system is 2 (mod 35). The solution to the second system
is 12 (mod 35). The solution to the third system is 23 (mod 35). The solution
to the fourth system is 33 (mod 35).
Now we have:
32
Exercises for Section 5
A Exercises
Exercise 40 Solve the following systems of two modular equations with the
Chinese Remainder Theorem.
1.
x ≡ 2 (mod 11)
x ≡ 7 (mod 9).
2.
x ≡ 4 (mod 5)
x ≡ 1 (mod 7).
3.
x ≡ 3 (mod 17)
x ≡ 12 (mod 13).
4.
x ≡ 5 (mod 9)
x ≡ 7 (mod 10).
5.
x ≡ 6 (mod 8)
x ≡ 11 (mod 15).
6.
x ≡ 13 (mod 14)
x ≡ 11 (mod 19).
Exercise 41 Solve the following systems of three modular equations with the
Chinese Remainder Theorem.
1.
x ≡ 2 (mod 3)
x ≡ 1 (mod 5)
x ≡ 6 (mod 8).
33
2.
x ≡ 3 (mod 5)
x ≡ 4 (mod 6)
x ≡ 2 (mod 11).
3.
x ≡ 1 (mod 3)
x ≡ 2 (mod 7)
x ≡ 11 (mod 13).
4.
x ≡ 5 (mod 6)
x ≡ 1 (mod 7)
x ≡ 6 (mod 11).
5.
x ≡ 12 (mod 13)
x ≡ 14 (mod 15)
x ≡ 16 (mod 17).
6.
x ≡ 4 (mod 7)
x ≡ 5 (mod 9)
x ≡ 2 (mod 10).
B Exercises
Exercise 42 Determine when a system of two modular congruences has more
than one solution.
Exercise 43 Determine when a system of two modular congruences has no
solutions.
Exercise 44 Find 4 square roots of 9 in Z143 .
Exercise 45 Find 4 square roots of 1 in Z299 .
C Exercises
Exercise 46 Write a program to implement the algorithm for solving the Chi-
nese Remainder Theorem.
34
6 Divisibility tests
We can return to the divisibility tests that we found in Chapter ??. Modular
arithmetic makes them all much easier. We begin with an easy lemma.
Proof: Most of the proofs are shown by showing that the two expressions
are congruent modulo the number we are testing for divisibility.
1. We have n = al 10l + al−1 10l−1 + · · · + a1 10 + a0 (mod 2) = a0 since 10 ≡ 0
(mod 2).
2. We have n = al 10l + al−1 10l−1 + · · · + a1 10 + a0 (mod 3) = al + al−1 +
· · · + a1 + a0 since 10 ≡ 1 (mod 3).
3. We have n = al 10l + al−1 10l−1 + · · · + a1 10 + a0 (mod 4) = 10a1 + a0 since
100 ≡ 0 (mod 4).
4. We have n = al 10l + al−1 10l−1 + · · · + a1 10 + a0 (mod 5) = a0 since 10 ≡ 0
(mod 5).
35
5. For divisibility by 6 we simply apply the rules for divisibility by 2 and 3.
6. For divisibility by 7 a slightly different approach is used. If
10a + b ≡ 0 (mod 7)
3a + b ≡ 0 (mod 7)
b ≡ 4a (mod 7).
The rule for divisibility by 7 is quite different from the other rules as we
exhibit in the following example.
We can get many more tests by writing the number n in different bases.
36
2. An integer n is divisible by b − 1 if and only if a0 + a1 + · · · + al is divisible
by b − 1.
Proof:
1. The first result comes from the fact that
n = al bl + al−1 bl−1 + · · · + a1 b + a0 (mod b) = a0 .
2. For the second result, note that b ≡ 1 (mod b − 1), which gives
n = al bl + al−1 bl−1 + · · · + a1 b + a0 (mod b − 1) = a0 + a1 + a2 + · · · + al .
We shall exhibit some of the power of the modular arithmetic in the following
theorems.
It is well known that there are infinitely many primes, see [?]. It is not
known if there are infinitely many twin primes, meaning primes of the form p,
p + 2 where both are prime. An example, would be 5 and 7. Another would be
41 and 43. We shall show that there is only one triple primes, namely primes
of the form p, p + 2, p + 4, where they are all primes.
Theorem 16 The only set of triple primes are 3, 5, and 7.
37
Theorem 18 There are arbitrarily long sequences of composite integers.
B Exercises
C Exercises
38
7 Train ride problem
Two friends, Leonhard and Emmy were traveling on a train. Since the trip was
quite long, Leonhard decided to ask Emmy a series of questions on modular
arithmetic where each answer depends on the previous answer that was given.
Therefore, each question must be answered correctly or the next answer will be
incorrect as well. See if you can determine the correct answer that Emmy gives
her friend at the end.
X ≡ 2 (mod a)
X ≡ 6 (mod b)
X ≡ k (mod 10)
X ≡ k+1 (mod 11)
39
20. Let t be the number of non-zero zero divisors in Zs .
21. Let u = t3 + 1 (mod 11).
22. Let v = (u + 5)4 (mod 11).
23. Let w be the number of units in Zv .
24. Let x be the unique solution in Z30 to the following system:
X ≡ w (mod 2)
X ≡ w+1 (mod 3)
X ≡ w+2 (mod 5)
Solution to Exercise 1
1. 5
2. 6
3. 7
4. 0
5. 1
6. 2
7. 10
8. 3
9. 1
10. 0
Solution to Exercise 2
1. 8
2. 1
3. 5
4. 1
5. 3
40
6. 2
7. 6
8. 1
9. 1
10. 0
Solution to Exercise 3
1.
31 ≡ 3 (mod 10)
2
3 ≡ 9 (mod 10)
3
3 ≡ 7 (mod 10)
34 ≡ 1 (mod 10)
Hence 322 = (34 )5 32 ≡ 1 · 32 = 9 (mod 10).
2.
41 ≡ 4 (mod 10)
2
4 ≡ 6 (mod 10)
43 ≡ 4 (mod 10)
4
4 ≡ 6 (mod 10)
.. .. ..
. . .
which will continue in the same manner. So we have that odd power give
4 and even powers give 6 modulo 10. Hence 4162 ≡ 6 (mod 10).
3.
51 ≡ 5 (mod 10)
2
5 ≡ 5 (mod 10)
53 ≡ 5 (mod 10)
.. .. ..
. . .
which will continue in the same manner. So we have that all the powers
of 5 give 5 modulo 10. Hence 510598 ≡ 5 (mod 10).
4.
61 ≡ 6 (mod 10)
2
6 ≡ 6 (mod 10)
3
6 ≡ 6 (mod 10)
.. .. ..
. . .
which will continue in the same manner. So we have that all the powers
of 6 give 6 modulo 10. Hence 65679 ≡ 6 (mod 10).
41
5. We have that 11 ≡ 1 (mod 10) which gives 11k ≡ 1 (mod 10) for any k.
6.
71 ≡ 7 (mod 10)
2
7 ≡ 9 (mod 10)
73 ≡ 3 (mod 10)
4
7 ≡ 1 (mod 10)
81 ≡ 8 (mod 10)
2
8 ≡ 4 (mod 10)
83 ≡ 2 (mod 10)
4
8 ≡ 6 (mod 10)
5
8 ≡ 8 (mod 10)
6
8 ≡ 4 (mod 10)
.. .. ..
. . .
Solution to Exercise 4
We have 53 ≡ 25 (mod 93). Hence we have that 53n ≡ 25n (mod 93) for n ∈
N. Multiplying the both sides of the last equation by 24 we have 53n · 24 ≡ 25n+4
(mod 93). Now multiplying both sides of the last equation by 4 we get
Solution to Exercise 5
x 0 1 2 3 4 5 6 7 8 9 10 11 12
x2 (mod 13) 0 1 4 9 3 12 10 10 12 3 9 4 1
Solution to Exercise 6
42
x 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
x2 (mod 16) 0 1 4 9 0 9 4 1 0 1 4 9 0 9 4 1
Solution to Exercise 7
x 0 1 2 3 4 5 6 7 8
x3 (mod 9) 0 1 8 0 1 8 0 1 8
Solution to Exercise 8
x 0 1 2 3 4 5 6 7 8 9
x4 (mod 10) 0 1 6 1 6 5 6 1 6 1
Solution to Exercise 9
0, 1, 7, 9, 15
Solution to Exercise 10
0, 5, 8.
Solution to Exercise 11
We have k(k) = n ≡ 0 (mod n).
Solution to Exercise 12
+ 0 1 2 3 4 · 0 1 2 3 4
0 0 1 2 3 4 0 0 0 0 0 0
1 1 2 3 4 0 1 0 1 2 3 4
2 2 3 4 0 1 2 0 2 4 1 3
3 3 4 0 1 2 3 0 3 1 4 2
3 4 0 1 2 3 4 0 4 3 2 1
Solution to Exercise 13
48
Solution to Exercise 14
2p − 1
Solution to Exercise 15
4
Solution to Exercise 16
p−1
Solution to Exercise 17
6, p − 1
Solution to Exercise 18
43
We have ac ≡ bc (mod n) implies n | (bc − ac) which means that n | (b − a)c.
Therefore, n | (b − a) since gcd(c, n) = 1. Hence b − a ≡ 0 (mod n) which means
that a ≡ b (mod n).
Solution to Exercise 19
Multiply each side of the equivalence b ≡ d (mod n) by c then we have
bc ≡ dc (mod n). We are also given ab ≡ cd (mod n). So we have that ab ≡ bc
(mod n) which implies that n | bc − ab which implies that n | b(c − a). So we
have that n | (c − a) since gcd(b, n) = 1. Hence c − a ≡ 0 (mod n) which means
that a ≡ c (mod n).
Solution to Exercise 22
1. 1, 5, 7, 11
2. 1, 5, 7, 11, 13, 17
3. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
4. 1, 3, 5, 7
5. 1, 3, 5, 7, 9, 11, 13, 15
Solution to Exercise 23
1. 2, 3, 4, 6, 8, 9, 10
2. 2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16
3. None.
4. 2, 4, 6
5. 2, 4, 6, 8, 10, 12, 14
Solution to Exercise 24
44
8. 15−1 ≡ 47 (mod 64)
9. 51−1 ≡ 39 (mod 71)
Solution to Exercise 25
1. 16
2. 26
3. 10
4. 3
5. 13
6. 7
7. 3
8. 211
9. 259
10. 25
Solution to Exercise 26
Z8
Nilpotent: 0, 2, 4, 6
Idempotent: 0, 1
Z10
Nilpotent: 0
Idempotent: 0, 1, 5, 6
Z16
Nilpotent: 0, 2, 4, 6, 8, 10, 12, 14
Idempotent: 0, 1
Solution to Exercise 27
If a = 2g then a2k−1 = 2k g ≡ 0 (mod 2k ). Therefore, if a is even, then a is
a zero-divisor and hence not a unit.
If a is odd, then gcd(a, 2k ) = 1 and so a is a unit.
Solution to Exercise 28
If a is not relatively prime to n then it is a zero divisor. Hence, if it is not a
zero divisor then it is relatively prime to n and therefore a unit.
Solution to Exercise 29
If a2 ≡ 1 (mod n), then a2 − 1 ≡ 0 (mod n). Then (a − 1)(a + 1) ≡ 0
(mod n). If a 6≡ ±1 then a − 1 and a + 1 are non-zero numbers whose product
is 0. Therefore, they are zero-divisors.
45
Solution to Exercise 30
Let a ∈ Zn . If gcd(a, n) = 1 then a is a unit. If gcd(a, n) 6= 1 then a is a
zero divisor.
In the integers, the number 2 is neither a unit nor a zero divisor. In fcat,
the only units are 1 and −1 and there are no zero divisors.
Solution to Exercise 32
1. x ≡ 4 (mod 7)
2. x ≡ 4 (mod 11)
3. x ≡ 8 (mod 9)
4. x ≡ 9 (mod 13)
5. x ≡ 6 (mod 15)
6. x ≡ 1600 (mod 1601)
7. x ≡ 15 (mod 32)
8. x ≡ 15 (mod 16)
Solution to Exercise 33
1. 2, 5, 8, 11 (mod 12)
2. 2, 5, 8 (mod 9)
3. No solution.
4. 4, 9, 14, 19 (mod 20)
5. 3, 7, 11 (mod 12)
6. No solution.
7. 2, 5, 8, 11, 14, 17 (mod 18)
8. 2, 5, 8, 11, 14 (mod 15)
Solution to Exercise 34
1. 3 (mod 11)
2. 8 (mod 13)
3. 4 (mod 10)
4. 1 (mod 17)
46
5. 18 (mod 24)
6. 72 (mod 73)
7. 3 (mod 15)
8. 0 (mod 14)
Solution to Exercise 35
1. Since gcd(2, 5) = 1 and 1 | 83, the equation does have a solution. We
apply the Euclidean Algorithm.
5 2 1 0
The computations are as follows.
5 = 2·2+1
2 = 1·2+0
We have
1 = 5 + 2 · (−2)
We multiply both sides of the equation by 83 and we get
1 · 83 = 5 · 83 + 2 · (−2) · 83
which means
83 = 2 · (−166) + 5 · 83
From the last equation we have that x0 = −166 and y0 = 83 and so that
x = −166 + 5k, y = 83 − 2k, k ∈ Z.
2. Since gcd(17, 83) = 1 and 1 | 135, the equation does have a solution. We
apply the Euclidean Algorithm.
83 17 15 2 1 0
The computations are as follows.
83 = 17 · 4 + 15
17 = 15 · 1 + 2
15 = 2·7+1
2 = 1·2+0
We have
1 = 15 + 2 · (−7)
= 15 + (17 + 15 · (−1)) · (−7)
= 15 · 8 + 17 · (−7)
= (83 + 17 · (−4)) · 8 + 17 · (−7)
= 17 · (−39) + 83 · 8.
47
We multiply both sides of the equation by 135 :
38 20 18 2 0
38 = 20 · 1 + 18
20 = 18 · 1 + 2
18 = 2·9+0
We have
2 = 20 + 18 · (−1)
= 20 + (38 + 20 · (−1)) · (−1)
= 20 · 2 + 38 · (−1)
20 · 56 + 38 · (−28) = 56
33 20 13 7 6 1 0
33 = 20 · 1 + 13
20 = 13 · 1 + 7
13 = 7·1+6
7 = 6·1+1
6 = 1·6+0
48
We have
1 = 7 + 6 · (−1)
= 7 + (13 + 7(−1)) · (−1)
= 7 · 2 + 13 · (−1)
= (20 + 13 · (−1)) · 2 + 13 · (−1)
= 20 · 2 + 13 · (−3)
= 20 · 2 + (33 − 20) · −3
= 20(5) − 3(33).
20 · 18 + (−13) · 27 = 9
41 12 5 2 1 0
41 = 12 · 3 + 5
12 = 5·2+2
5 = 2·2+1
2 = 1·2+0
We have
1 = 5 + 2 · (−2)
= 5 + (12 + 5(−2)) · (−2)
= 5 · 5 + 12 · (−2)
= (41 + 12 · (−3)) · 5 + 12 · (−2)
= 41 · 5 + 12 · (−17)
41 · (−35) + 12 · 119 = −7
49
8. Since gcd(405, 804) = 3 and 3 | 3, the equation does have a solution. We
apply the Euclidean Algorithm.
We have
3 = 399 + 6 · (−66)
= 399 + (405 + 399(−1)) · (−66)
= 399 · 67 + 405 · (−66)
= (804 + 405 · (−1)) · 67 + 405 · (−66)
= 405 · (−133) + 804 · 67
Hence we have
405 · (−133) + 804 · 67 = 3.
So x0 = −133, y0 = 67 and x = −133 + 804k, y = 67 − 405k, k ∈ Z.
9. We have the following Diophantine equation 286x + 230y = 6531. We have
that gcd(286, 230) = 2 but 2 - 6531, the equation does not have a solution.
Solution to Exercise 36
If a is a square, that is a = b2 (mod p), and x2 ≡ b2 (mod p). Then (x −
b)(x+b) ≡ 0 (mod p). There are no zero divisors in Zp , p a prime, so no element
other that b or −b can make this product 0. Therefore, there are at most two
solutions.
Solution to Exercise 37
The equation x2 ≡ −1 (mod 5) has two solutions, 2 and 3.
The equation x2 ≡ −1 (mod 7) has no solution.
Solution to Exercise 40
1. 79 (mod 99)
2. 29 (mod 35)
3. 207 (mod 221)
4. 77 (mod 90)
50
5. 86 (mod 120)
6. 125 (mod 266)
Solution to Exercise 41
1. 86 (mod 120)
2. 178 (mod 330)
3. 37 (mod 273)
4. 281 (mod 462)
5. 3314 (mod 3315)
6. 32 (mod 630)
Solution to Exercise 42
Consider the following system of equations:
x ≡ a (mod n)
x ≡ b (mod m).
Solution to Exercise 43
Consider the following system of equations:
x ≡ a (mod n)
x ≡ b (mod m).
Solution to Exercise 44
3, 36, 107, 140 (mod 143)
Solution to Exercise 45
1, 116, 183, 298 (mod 299)
51
Solutions to Exercises for Section 6
Solution to Exercise 47
1. 1, 2, 3, 4, 6, 8, 9.
2. 1, 2, 4.
3. 1, 3.
4. 1, 2, 7, 11.
5. 1, 2, 11.
6. 1, 2, 3, 4, 6, 8, 9.
7. 1.
8. 1, 5, 7.
9. 1, 2, 4, 5, 10.
10. 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11.
Solution to Exercise 48
A number is divisible by 12 if the sum of its digits is divisible by 3 and its
last two digits (as a two digit number) is divisible by 4.
Solution to Exercise 49
A number is divisible by 15 if the sum of its digits is divisible by 3 and its
last digit is either 0 or 5.
Solution to Exercise 50
A number is divisible by 16 if its last 4 digits (as a 4 digit number is divisible
by 16.
Solution to Exercise 51
A number is divisible by 20 if the its last two digits (as a two digit number)
is divisible by 4 and it ends in 0.
52