4.7 Notes and Exercises
4.7 Notes and Exercises
7 Euclidean algorithm
One way of finding the greatest common divisor uses the prime factorizations:
Example: 84 = 22A3A7 and 60 = 22A3A5. Clearly the gcd(84, 60) = 22A3 = 12
For large numbers this approach may be difficult.
The Euclidean Algorithm uses the fact that the greatest common divisor of two integers must be a factor
of the difference of the integers. If m = nq + r, then the gcd must also divide the remainder r.
Example We will see by the Euclidean Algorithm that gcd(84, 60) = 12:
84 – 60×(1) = 24
60 – 24×(2) = 12
24 – 12×(2) = 0, so gcd(84, 60) = gcd(60, 24) = gcd(24, 12) = gcd(12, 0) = 12
We illustrate first a method of finding these multipliers s and t by reversing the calculations of the
Euclidean Algorithm. Later we show a direct way of finding s and t using the Extended Euclidean
Algorithm
Rewriting these equations in reverse:
12 = 60 + 24×(-2)
24 = 84 + 60×(-1)
Replacing 24 in the first equation yields 12 = 60 + [84 + 60×(-1)]×(-2) = 84×(-2) + 60×(3).
The Extended Euclidean Algorithm can be used to find the gcd of two numbers and express it as a
linear combination of those numbers. It uses auxiliary numbers 1 and 0 and two starting conditions to
produce an invariant expression G = S×A + T×B that yields the desired result.
Lemma If a, b, c are positive integers such that gcd(a, b) = 1 and if a | bc, then a | c.
Proof: Set 1 = sa + tb and multiply by c, getting c = sac + tbc.
Since a divides any multiple of itself and any multiple of bc, a | sac and a | tbc, so it must divide c.
Lemma A prime that divides a product of integers must divide at least one of the factors.
To find the modular inverse of 2 (mod 7), consider that gcd(7, 2) = 1 = (1)7 + (-3)2. Reducing this
equation (mod 7), where 0 replaces 7, and 4 replaces (-3) produces 1 / 0 + (4)2 (mod 7). Now to solve
the linear congruence 2x / 5 (mod 7) we multiply by 4, which is the modular inverse of 2 :
8x / 20 (mod 7) which reduces to x / 6 (mod 7).
To find the modular inverse of 3 (mod 13), consider that gcd(13, 3) = 1 = (1)13 + (-4)3. Reducing this
equation (mod 13), where 0 replaces 13, and 9 replaces (-4) produces 1 / 0 + (9)3 (mod 13). Now to
solve the linear congruence 3x / 7 (mod 13) we multiply by 9, which is the modular inverse of 3:
27x / 63 (mod 13) which reduces to x / 11 (mod 13)
To find the modular inverse of 21 (mod 26), consider that gcd(26, 21) = 1 = (-4)26 + (5)21. Reducing
the equation (mod 26), where 0 replaces 26, and 5 stands for itself produces 1 / 0 + (5)21 (mod 26).
Now to solve the linear congruence 21x / 3 (mod 26) we multiply by 5, which is the modular inverse
of 21: 105x / 15 (mod 26) which reduces to x / 15 (mod 26).
4.7 Euclidean Algorithm p178. 1, 3, 5, 7, 9
1. Use any method to find gcd(m, n)
a) gcd(20, 20) = 20 b) gcd(20, 10) = 10 c) gcd(20, 1) = 1 d) gcd(20, 0) = 20
e) gcd(20, 72) = gcd(72, 20 MOD 72) = gcd(72, 20) = gcd(20, 72 MOD 20) = gcd(20, 12)
= gcd(12, 20 MOD 12) = gcd(12, 8) = gcd(8, 12 MOD 8) = gcd(8, 4) = gcd(4, 8 MOD 4) = gcd(4, 0) = 4
f) gcd(20, -20) = gcd( 20, 20) = 20
g) gcd(120, 162) = gcd(162, 120) = gcd(120, 42) = gcd(42, 36) = gcd(36, 6) = gcd(6, 0) = 6
h) gcd(20, 27) = gcd(27, 20) = gcd(20, 7) = gcd(7, 6) = gcd(6, 1) = 1
3. List the pairs (a, b) that arise AlgorithmGCD is applied to the numbers m, n, and find gcd(m, n).
a) gcd(20, 14): (20, 14), (14, 6), (6, 2), (2, 0); gcd(20, 14) = 2
b) gcd(20, 7): (20, 7), (7, 6), (6, 1), (1, 0); gcd(20, 7) = 1
c) gcd(20, 30): (20, 30), (30, 20), (20, 10), (10, 0); gcd(20, 30) = 10
d) gcd(2000, 987): (2000, 987), (987, 26), (26, 25), (25, 1), (1, 0); gcd(2000, 987) = 1
5. Use the Euclidean Algorithm to find gcd(m, n) and integers s and t such that gcd(m, n) = sm + tn.
a) gcd(20, 14) = 2 = (-2)20 + (3)14
a q s t
20 1 0
14 1 0 1
6 2 1 -1
2 3 -2 3
0