0% found this document useful (0 votes)
392 views7 pages

Modular Arithmetic PDF

The document defines modular arithmetic and congruence relations modulo m. It shows that congruence modulo m is an equivalence relation, and explores properties of addition and multiplication modulo m. Examples are provided to demonstrate working with congruences, finding multiplicative inverses, and solving congruences. The binomial theorem is also proved modulo a prime number p.

Uploaded by

ronmark
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)
392 views7 pages

Modular Arithmetic PDF

The document defines modular arithmetic and congruence relations modulo m. It shows that congruence modulo m is an equivalence relation, and explores properties of addition and multiplication modulo m. Examples are provided to demonstrate working with congruences, finding multiplicative inverses, and solving congruences. The binomial theorem is also proved modulo a prime number p.

Uploaded by

ronmark
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/ 7

2-16-2019

Modular Arithmetic
Definiton. Let a, b, and m be integers. a = b (mod m) (read “a equals b mod m” or a is congruent to b
mod m) if any of the following equivalent conditions hold:

(a) m | a − b.

(b) m | b − a.

(c) a = b + jm (or a − b = jm) for some j ∈ Z.

(d) b = a + km (or b − a = km) for some k ∈ Z.

m is called the modulus of the congruence. I will almost always work with positive moduli.
Note that a = 0 (mod m) if and only if m | a. Thus, modular arithmetic gives you another way of
dealing with divisibility relations. Another way of saying this is: Mod m any multiple of m is 0.

Remark. Many people prefer to write “a ≡ b (mod m)”. Since equality mod m is an equivalence relation,
since “=” is a little less writing than “≡”, and since there isn’t much risk of confusion, I’ll write “=”.

Example.

(a) Reduce 101 (mod 3) to a number in the range {0, 1, 2}.

(b) Reduce −101 (mod 3) to a number in the range {0, 1, 2}.

(a) 101 = 2 (mod 3), because 3 | 101 − 2 = 99.

(b) −101 = 1 (mod 3), because 3 | −101 − 1 = −102.

Proposition. Congruence mod m is an equivalence relation:

(a) (Reflexivity) a = a (mod m) for all a.

(b) (Symmetry) If a = b (mod m), then b = a(mod m).

(c) (Transitivity) If a = b (mod m) and b = c (mod m), then a = c (mod m).

Proof. I’ll prove transitivity by way of example. Suppose a = b (mod m) and b = c (mod m). Then there
are integers j and k such that
a − b = jm, b − c = km.
Add the two equations:
a − c = (j + k)m.
This implies that a = c (mod m).

Theorem. Suppose a = b (mod m) and c = d (mod m). Then:

(a) a + c = b + d (mod m).

(b) ac = bd (mod m).

1
Note that you can use the second property and induction to show that if a = b (mod m), then

an = bn (mod m) for all n ≥ 1.

Proof. Suppose a = b (mod m) and c = d (mod m).

(a) m | a − b and m | c − d, so by properties of divisibility,

m | (a − b) + (c − d) = (a + c) − (b + d).

This implies that a + c = b + d (mod m).

(b) m | a − b and m | c − d imply that there are integers j and k such that

a = b + mj and c = d + mk.

Multiplying these two equations, I obtain

ac = (b + mj)(d + mk)
ac = bd + m(dj + bk + mjk)
ac − bd = m(dj + bk + mjk)

Hence, m | ac − bd, so ac = bd (mod m).

Corollary. Suppose a = b (mod m). Then:

(a) a ± c = b ± c (mod m).

(b) ac = bc (mod m).

Proof. Apply the theorem to the equations a = b (mod m) and c = c (mod m).

Assume that the modulus m is a positive integer. By the Division Algorithm, every integer n can be
written as
n = qm + r where 0 ≤ r < m.
Reducing this equation mod m, I have qm = 0 (mod m), so

n = r (mod m) .

Since 0 ≤ r < m, I have r ∈ {0, 1, . . . m − 1}. In other words, mod m every integer can be reduced to
a number in {0, 1, . . . m − 1}. This set is called the standard residue system mod m, and answers to
modular arithmetic problems will usually be simplified to a number in this range.

Example. (a) What are the equivalence classes under the relation of congruence mod 3?

(b) Construct an addition table for addition mod 3.

(a) Consider congruence mod 3. There are 3 congruence classes:

{. . . , −3, 0, 3, 6, . . .}, {. . . − 4, −1, 2, 5, . . .}, {. . . − 5, −2, 1, 4, . . .}.

Each integer belongs to exactly one of these classes. Two integers in a given class are congruent mod 3.
(If you know some group theory, you probably recognize this as constructing Z3 from Z.)

(b) When you’re doing things mod 3, it is if there were only 3 numbers. I’ll grab one number from each of
the classes to represent the classes; for simplicity, I’ll use 0, 2, and 1.

2
Here is an addition table for the classes in terms of these representatives:

+ 0 1 2
0 0 1 2
1 1 2 0
2 2 0 1

Here’s an example: 2 + 1 = 0, because 2 + 1 = 3 as integers, and 3’s congruence class is represented by


0. This is the table for addition mod 3.
I could have chosen different representatives for the classes — say 3, −4, and 4, but I would have gotten
an equivalent table. The simplest thing is to use the numbers {0, 1, 2} from the standard residue system
mod 3.

Example. (Reducing an expression mod n) Reduce 1005 (mod 7) to an element in the standard residue
system {0, 1, . . . , 6}.

100 = 2 (mod 7), so


1005 = 25 = 32 = 4 (mod 7) .

Example. Simplify 994 · 996 · 997 · 998 (mod 1000) to a number in the range {0, 1, . . . 999}.

Rather than deal with large “positive” numbers, I’ll convert them to small “negative” numbers:

994 = −6 (mod 1000) , 996 = −4 (mod 1000) , 997 = −3 (mod 1000) , 998 = −2 (mod 1000) .

So
994 · 996 · 997 · 998 = (−6)(−4)(−3)(−2) = 144 (mod 1000) .

Example. (A modular binomial theorem) Prove that if p is prime, then

(x + y)p = xp + y p (mod p) .

By the Binomial Theorem,


p  
X p i p−i
(x + y)p = xy .
i=0
i
 
p p!
A typical coefficient = is divisible by p for i 6= 0, p. So going mod p, the only terms that
i i! (p − i)!
p p
remain are x and y .
For example

(x + y)2 = x2 + y 2 (mod 2) and (x + y)3 = x3 + y 3 (mod 3) .

The result is not true if the modulus is not prime. For example,

(1 + 1)4 = 0 (mod 4) , but 14 + 14 = 2 (mod 4) .

3
Example. Prove that if x ∈ Z, then 4x2 + x + 3 is not divisible by 5.

The phrase “not divisible by 5” leads one to think of doing things mod 5.
Every integer is equal to one of 0, 1, 2, 3, or 4 mod 5. Make a table:

x (mod 5) 0 1 2 3 4
4x2 + x + 3 (mod 5) 3 3 1 2 1

From the table, 4x2 + x + 3 6= 0 (mod 5) for all x ∈ Z, so 5 6 | 4x2 + x + 3 for all x ∈ Z.

Example. Give a counterexample to show that a = b (mod n) does not imply that xa = xb (mod n), for
a, b, n, x ∈ Z.

For instance, 7 = 4 (mod 3), but 27 6= 24 (mod 3) (since 128 6= 16 (mod 3)).

Example. Solve the congruence


6x + 1 = 2(x + 2) (mod 7) .
The modular arithmetic properties allow me to solve this equation the way I would solve a linear equation,
up to a point. I multiply out the left side, then get the x’s on one side:

6x + 1 = 2(x + 2) (mod 7)
6x + 1 = 2x + 4 (mod 7)
4x = 3 (mod 7)

If this were an equation over the real numbers, you could divide both sides by 4 — equivalently, multiply
1
both sides by .
4
1
What would “ ” mean mod 7? This is the multiplicative inverse of 4, which we write as 4−1 (in modular
4
arithmetic you don’t use fraction notation). This means: What number multiplied by 4 gives 1 mod 7?
Since there are only 7 numbers mod 7, I can do this by trial and error, multiplying 4 by 0, 1, . . . until I
get 1. I find that
2 · 4 = 8 = 1 (mod 7) .
So for this modular equation, I multiply both sides by 2:

2 · 4x = 2 · 3 (mod 7)
8x = 6 (mod 7)
x = 6 (mod 7)

You can see that finding multiplicative inverses mod n can be useful in solving congruences. Sometimes
they can be found by more refined trial and error than simply trying all the numbers mod n.
Since multiples of n equal 0 mod n,

1 = 1 + n = 1 + 2n = 1 + 3n = · · · (mod n) .

I can sometimes use this to find inverses mod n.

4
Example.

(a) Use trial and error to find 5−1 (mod 7).

(b) Use trial and error to find 45−1 (mod 89).

(c) Prove that 25 does not have a multiplicative inverse mod 30.

(a) I take multiples of 7 and add 1, stopping when I get a number which is divisible by 5:

7 + 1 = 8, but 5 6 | 8.

14 + 1 = 15. and 5 | 15.


Since 3 · 5 = 15, I have 5−1 = 3 (mod 7).

(b) I take multiples of 89 and add 1, stopping when I get a number which is divisible by 45:

89 + 1 = 90, and 45 | 90.

Since 2 · 45 = 90, I have 45−1 = 2 (mod 90).

(c) Suppose that 25x = 1 (mod 30) (so x = 25−1 (mod 30)). Then

25x = 1 (mod 30)


6 · 25x = 6 · 1 (mod 30)
150x = 6 (mod 30)
0 = 6 (mod 30)

This contradiction shows that there is no such x, so 25 does not have a multiplicative inverse mod 30.

The previous method still has its limitations, as you can see by trying to use it to find 47−1 (mod 61).
And as you saw, some elements don’t have multiplicative inverses mod n. The following theorem says which
elements have multiplicative inverses, and how to find them if they exist.

Theorem. m has a multiplicative inverse mod n if and only if (m, n) = 1.

Proof. Suppose m has a multiplicative inverse mod n. This means that am = 1 (mod n) for some a. Then

am + bn = 1 for some b ∈ Z.

Hence, (m, n) = 1.
Conversely, if (m, n) = 1, then

am + bn = 1 for some a, b ∈ Z.

Reducing mod n, I get am = 1 (mod n), which means that m has a multiplicative inverse mod n.

As the proof shows, you can find a−1 (mod n) by applying the Extended Euclidean algorithm to a and
n.

Example. (Finding elements which have multiplicative inverses) Which elements of {0, 1, 2, . . . , 11}
have multiplicative inverses mod 12?

5
The numbers in {0, 1, 2, . . . , 11} which are relatively prime to 12 and 1, 5, 7, and 11. Hence, 1, 5, 7, and
11 have multiplicative inverses mod 12.

Example. Find 47−1 (mod 61).

Apply the Extended Euclidean Algorithm to 61 and 47:

61 - 13
47 1 10
14 3 3
5 2 1
4 1 1
1 4 0

Write the linear combination, then reduce mod 61:

(−10) · 61 + 13 · 47 = 1
13 · 47 = 1 (mod 61)

Hence, 47−1 = 13 (mod 61).

Proposition. If ac = bc (mod m), then


 
m
a=b mod .
(c, m)

Proof. Write
ac − bc = km, where k ∈ Z.
Then
c m
(a − b) =k .
(c, m) (c, m)
c m c
(Notice that and are integers, since (c, m) | c and (c, m) | m.) Now divides the
(c, m) (c, m) (c, m)
m
right side, but it’s relatively prime to . Therefore, it must divide k:
(c, m)
c
k= j for some j ∈ Z.
(c, m)

Hence,
c c m
(a − b) = j·
(c, m) (c, m) (c, m)
m
a−b=j·
(c, m)
 
m
Therefore, a = b mod .
(c, m)
Notice that you “divide the equality” by c, but you divide the modulus by (c, m).

6
Example. (Solving a congruence with cancellation) Solve

12x = 30 (mod 38) .

12x = 30 (mod 38)


6 · 2x = 6 · 5 (mod 38)
By the previous result, if I “cancel” the factors of 6, I must divide the modulus by (6, 38) = 2. This
makes the modulus 19:
6 · 2x = 6 · 5 (mod 38)
2x = 5 (mod 19)
Now (2, 19) = 1, so I can solve this congruence by multiplying by 2−1 (mod 19). Noting that 2 · 10 =
10 = 1 (mod 19), I see that I need to multiply by 10:

10 · 2x = 10 · 5 (mod 19)
20x = 50 (mod 19)
x = 12 (mod 19)

(If you didn’t see that 2−1 = 10 (mod 19) by trial, you’d use the Extended Euclidean algorithm as
before.)
The original congruence was mod 38, so I want all solutions in the range {0, 1, . . . 37. I have one: x = 12.
To get others, I add multiples of 19 until I exceed 37. Thus, x = 12 + 19 = 31 is the other solution.
All together, the solutions are x = 12 (mod 38) and x = 31 (mod 38).

Example. (A congruence with no solutions) Show that the following congruence has no solutions:

4x = 5 (mod 14) .

Suppose that x is a solution. Multiply the equation by 7:

4x = 5 (mod 14)
7 · 4x = 7 · 5 (mod 14)
28x = 35 (mod 14)
0 = 7 (mod 14)

This contradiction shows that the equation has no solutions.

These examples show that linear congruences may have solutions or may be unsolvable. We can under-
stand better what is happening by relating them to linear Diophantine equations.


c 2019 by Bruce Ikenaga 7

You might also like