2. INTEGERS AND ALGORITHMS
155
2. Integers and Algorithms
2.1. Euclidean Algorithm. Euclidean Algorithm.
Suppose
a
and
b
are in
tegers with
a
≥
b >
0.
(1) Apply the division algorithm:
a
=
bq
+
r
, 0
≤
r < b
.
(2) Rename
b
as
a
and
r
as
b
and repeat until
r
= 0.
The last nonzero remainder is the greatest common divisor of
a
and
b
.
The Euclidean Algorithm depends upon the following lemma.
Lemma
2.1.1
.
If
a
=
bq
+
r
, then
GCD(
a,b
) = GCD(
b,r
)
.
Proof.
We will show that if
a
=
bq
+
r
, then an integer
d
is a common divisor
of
a
and
b
if, and only if,
d
is a common divisor of
b
and
r
.
Let
d
be a common divisor of
a
and
b
. Then
d

a
and
d

b
. Thus
d

(
a

bq
), which
means
d

r
, since
r
=
a

bq
. Thus
d
is a common divisor of
b
and
r
.
Now suppose
d
is a common divisor of
b
and
r
. Then
d

b
and
d

r
. Thus
d

(
bq
+
r
),
so
d

a
. Therefore,
d
must be a common divisor of
a
and
b
.
Thus, the set of common divisors of
a
and
b
are the same as the set of common
divisors of
b
and
r
. It follows that
d
is the
greatest
common divisor of
a
and
b
if and
only if
d
is the greatest common divisor of
b
and
r
.
±
Discussion
The fact that the Euclidean algorithm actually gives the greatest common divi
sor of two integers follows from the division algorithm and the equality in Lemma
2.1.1. Applying the division algorithm repeatedly as indicated yields a sequence of
remainders
r
1
> r
2
>
···
> r
n
>
0 =
r
n
+1
, where
r
1
< b
. Lemma 2.1.1 says that
GCD(
a,b
) = GCD(
b,r
1
) = GCD(
r
1
,r
2
) =
···
= GCD(
r
n

1
,r
n
)
.
But, since
r
n
+1
= 0,
r
n
divides
r
n

1
, so that
GCD(
r
n

1
,r
n
) =
r
n
.
Thus, the last nonzero remainder is the greatest common divisor of
a
and
b
.
Example
2.1.1
.
Find
GCD
(1317, 56).