Lecture 5
Lecture 5
Lecture 5
3 / MODULAR ARITHMETIC 53
The Modulus
If a is an integer and n is a positive integer, we define a mod n to be the remainder
when a is divided by n. The integer n is called the modulus. Thus, for any integer a,
we can rewrite Equation (2.1) as follows:
a = qn + r 0 … r 6 n; q = : a/n ;
a = : a/n ; * n + (a mod n)
Properties of Congruences
Congruences have the following properties:
1. a K b (mod n) if n (a - b).
2. a K b (mod n) implies b K a (mod n).
3. a K b (mod n) and b K c (mod n) imply a K c (mod n).
To demonstrate the first point, if n (a - b), then (a - b) = kn for some k.
So we can write a = b + kn. Therefore, (a mod n) = (remainder when b +
kn is divided by n) = (remainder when b is divided by n) = (b mod n).
23 K 8 (mod 5) because 23 - 8 = 15 = 5 * 3
-11 K 5 (mod 8) because -11 - 5 = -16 = 8 * ( -2)
81 K 0 (mod 27) because 81 - 0 = 81 = 27 * 3
2
We have just used the operator mod in two different ways: first as a binary operator that produces a re-
mainder, as in the expression a mod b; second as a congruence relation that shows the equivalence of two
integers, as in the expression a K b (mod n). See Appendix 2A for a discussion.
54 CHAPTER 2 / INTRODUCTION TO NUMBER THEORY
The remaining properties are proven as easily. Here are examples of the three
properties:
11 mod 8 = 3; 15 mod 8 = 7
[(11 mod 8) + (15 mod 8)] mod 8 = 10 mod 8 = 2
(11 + 15) mod 8 = 26 mod 8 = 2
[(11 mod 8) - (15 mod 8)] mod 8 = -4 mod 8 = 4
(11 - 15) mod 8 = -4 mod 8 = 4
[(11 mod 8) * (15 mod 8)] mod 8 = 21 mod 8 = 5
(11 * 15) mod 8 = 165 mod 8 = 5
Thus, the rules for ordinary arithmetic involving addition, subtraction, and
multiplication carry over into modular arithmetic.
2.3 / MODULAR ARITHMETIC 55
Table 2.2 provides an illustration of modular addition and multiplication
modulo 8. Looking at addition, the results are straightforward, and there is a reg-
ular pattern to the matrix. Both matrices are symmetric about the main diagonal
in conformance to the commutative property of addition and multiplication. As in
ordinary addition, there is an additive inverse, or negative, to each integer in modu-
lar arithmetic. In this case, the negative of an integer x is the integer y such that
(x + y) mod 8 = 0. To find the additive inverse of an integer in the left-hand col-
umn, scan across the corresponding row of the matrix to find the value 0; the integer
at the top of that column is the additive inverse; thus, (2 + 6) mod 8 = 0. Similarly,
the entries in the multiplication table are straightforward. In modular arithmetic mod
8, the multiplicative inverse of x is the integer y such that (x * y) mod 8 = 1 mod 8.
Now, to find the multiplicative inverse of an integer from the multiplication table,
scan across the matrix in the row for that integer to find the value 1; the integer at
the top of that column is the multiplicative inverse; thus, (3 * 3) mod 8 = 1. Note
that not all integers mod 8 have a multiplicative inverse; more about that later.
Z n = {0, 1, c , (n - 1)}
* 0 1 2 3 4 5 6 7 w -w w -1
0 0 0 0 0 0 0 0 0 0 0 —
1 0 1 2 3 4 5 6 7 1 7 1
2 0 2 4 6 0 2 4 6 2 6 —
3 0 3 6 1 4 7 2 5 3 5 3
4 0 4 0 4 0 4 0 4 4 4 —
5 0 5 2 7 4 1 6 3 5 3 5
6 0 6 4 2 0 6 4 2 6 2 —
7 0 7 6 5 4 3 2 1 7 1 7
(b) Multiplication modulo 8 (c) Additive and multiplicative
inverse modulo 8
56 CHAPTER 2 / INTRODUCTION TO NUMBER THEORY
This is referred to as the set of residues, or residue classes (mod n). To be more pre-
cise, each integer in Z n represents a residue class. We can label the residue classes
(mod n) as [0], [1], [2], c , [n - 1], where
Of all the integers in a residue class, the smallest nonnegative integer is the
one used to represent the residue class. Finding the smallest nonnegative integer to
which k is congruent modulo n is called reducing k modulo n.
If we perform modular arithmetic within Z n, the properties shown in Table 2.3
hold for integers in Z n. We show in the next section that this implies that Z n is a
commutative ring with a multiplicative identity element.
There is one peculiarity of modular arithmetic that sets it apart from ordinary
arithmetic. First, observe that (as in ordinary arithmetic) we can write the following:
Property Expression
(w + x) mod n = (x + w) mod n
Commutative Laws
(w * x) mod n = (x * w) mod n
[(w + x) + y] mod n = [w + (x + y)] mod n
Associative Laws
[(w * x) * y] mod n = [w * (x * y)] mod n
Distributive Law [w * (x + y)] mod n = [(w * x) + (w * y)] mod n
(0 + w) mod n = w mod n
Identities
(1 * w) mod n = w mod n
Additive Inverse ( - w) For each w ∈ Z n, there exists a z such that w + z K 0 mod n
2.3 / MODULAR ARITHMETIC 57
However, the following statement is true only with the attached condition:
Recall that two integers are relatively prime if their only common positive integer
factor is 1. Similar to the case of Equation (2.4), we can say that Equation (2.5) is
consistent with the existence of a multiplicative inverse. Applying the multiplicative
inverse of a to both sides of Equation (2.5), we have
To see this, consider an example in which the condition of Equation (2.5) does not
hold. The integers 6 and 8 are not relatively prime, since they have the common
factor 2. We have the following:
6 * 3 = 18 K 2(mod 8)
6 * 7 = 42 K 2(mod 8)
Yet 3 [ 7 (mod 8).
The reason for this strange result is that for any general modulus n, a multi-
plier a that is applied in turn to the integers 0 through (n - 1) will fail to produce a
complete set of residues if a and n have any factors in common.
With a = 6 and n = 8,
Z8 0 1 2 3 4 5 6 7
Multiply by 6 0 6 12 18 24 30 36 42
Residues 0 6 4 2 0 6 4 2
Z8 0 1 2 3 4 5 6 7
Multiply by 5 0 5 10 15 20 25 30 35
Residues 0 5 2 7 4 1 6 3