The Euclidean Algorithm
Math 31 - Topics in Algebra
This is a summary of the important definitions and results associated to the Euclidean algorithm,
along with examples of the algorithm in action.
Theorem 1 (Division algorithm). Let n and m be integers, with m > 0. Then there exist integers
q and r, with 0 ≤ r ≤ n − 1, such that
n = qm + r.
Definition 1. • We say that an integer m divides an integer n if there exists c ∈ Z such that
n = cm.
• The greatest common divisor of a and b, gcd(a, b), is the largest positive integer which
divides both a and b.
• We say that a and b are relatively prime if gcd(a, b) = 1.
Euclidean algorithm: Given integers n and m (suppose that m < n), gcd(n, m) can be com-
puted as follows:
1. Use the Division Algorithm to write
n = q0 m + r0 .
2. Apply the Division Algorithm again to write
m = q1 r0 + r1 ,
i.e., to obtain a new quotient and remainder.
3. Continue this process until you obtain a remainder of zero. The previous (nonzero) remain-
der is gcd(n, m).
Theorem 2. Let n, m ∈ Z. There exist integers x and y such that
gcd(n, m) = nx + my.
1
Example 2. Find gcd(105, 81).
Solution. We divide each remainder into the previous divisor:
105 = 1 · 81 + 24
81 = 3 · 24 + 9
24 = 2 · 9 + 6
9=1·6+3
6=2·3+0
We’ve reached a remainder of 0, so we stop. The last nonzero remainder is 3, so
gcd(105, 81) = 3.
Example 3. Finding gcd(343, 210).
Solution. Run through the Euclidean algorithm until we hit 0:
343 = 1 · 210 + 133
210 = 1 · 133 + 77
133 = 1 · 77 + 56
77 = 1 · 56 + 21
56 = 2 · 21 + 14
21 = 1 · 14 + 7
14 = 2 · 7 + 0
Then we see that gcd(343, 210) = 7.