Euclid’s algorithm

Euclid’s algorithm

Euclid’s

algorithm

describes a procedure for finding the

greatest common divisor

of two

integers

.

Suppose

a

,

b

∈

ℤ

, and without loss of generality,

b

>

0

, because if

b

<

0

,
then

gcd

⁡

(

a

,

b

)

=

gcd

⁡

(

a

,

|

b

|

)

, and if

b

=

0

, then

gcd

⁡

(

a

,

b

)

=

|

a

|

.
Put

d

:=

gcd

⁡

(

a

,

b

)

.

By the

division algorithm for integers

, we may find integers

q

and

r

such that

a

=

q

0

⁢

b

+

r

0

where

0

≤

r

0

<

b

.

Notice that

gcd

⁡

(

a

,

b

)

=

gcd

⁡

(

b

,

r

0

)

, because

d

∣

a

and

d

∣

b

, so

d

∣

r

0

=

a

-

q

0

b

and
if

b

and

r

0

had a common

divisor

d

′

larger than

d

, then

d

′

would also be a common divisor of

a

and

b

, contradicting

d

’s maximality. Thus,

d

=

gcd

⁡

(

b

,

r

0

)

.

So we may repeat the division, this time with

b

and

r

0

. Proceeding recursively, we obtain

a

=

q

0

⁢

b

+

r

0

⁢

with

⁢

0

≤

r

0

<

b

b

=

q

1

⁢

r

0

+

r

1

⁢

with

⁢

0

≤

r

1

<

r

0

r

0

=

q

2

⁢

r

1

+

r

2

⁢

with

⁢

0

≤

r

2

<

r

1

r

1

=

q

3

⁢

r

2

+

r

3

⁢

with

⁢

0

≤

r

3

<

r

2

⋮

Thus we obtain a

decreasing sequence

of

nonnegative integers

b

>

r

0

>

r

1

>

r

2

>

…

, which
must

eventually

reach zero, that is to say,

r

n

=

0

for some

n

, and the algorithm terminates. We may easily generalize the previous

argument

to show that

d

=

gcd

⁡

(

r

k

-

1

,

r

k

)

=

gcd

⁡

(

r

k

,

r

k

+

1

)

for

k

=

0

,

1

,

2

,

…

,
where

r

-

1

=

b

. Therefore,

d

=

gcd

⁡

(

r

n

-

1

,

r

n

)

=

gcd

⁡

(

r

n

-

1

,

0

)

=

r

n

-

1

.

More
colloquially, the greatest common divisor is the last nonzero

remainder

in the algorithm.

The algorithm provides a bit more than this. It also yields a way to express the

d

as a

linear
combination

of

a

and

b

, a fact obscurely known as Bezout’s lemma. For we have that

a

-

q

0

⁢

b

=

r

0

b

-

q

1

⁢

r

0

=

r

1

r

0

-

q

2

⁢

r

1

=

r

2

r

1

-

q

3

⁢

r

2

=

r

3

⋮

r

n

-

3

-

q

n

-

1

⁢

r

n

-

2

=

r

n

-

1

r

n

-

2

=

q

n

⁢

r

n

-

1

so substituting each remainder

r

k

into the next equation we obtain

b

-

q

1

⁢

(

a

-

q

0

⁢

b

)

=

k

1

⁢

a

+

l

1

⁢

b

=

r

1

(

a

-

q

0

⁢

b

)

-

q

2

⁢

(

k

1

⁢

a

+

l

1

⁢

b

)

=

k

2

⁢

a

+

l

2

⁢

b

=

r

2

(

k

1

⁢

a

+

l

1

⁢

b

)

-

q

3

⁢

(

k

2

⁢

a

+

l

2

⁢

b

)

=

k

3

⁢

a

+

l

3

⁢

b

=

r

3

⋮

⋮

(

k

n

-

3

⁢

a

+

l

n

-

3

⁢

b

)

-

q

n

⁢

(

k

n

-

2

⁢

a

+

l

n

-

2

⁢

b

)

=

k

n

-

1

⁢

a

+

l

n

-

1

⁢

b

=

r

n

-

1

Sometimes, especially for manual

computations

, it is preferable to write all the algorithm in a tabular
format. As an example, let us apply the algorithm to

a

=

756

and

b

=

595

. The following table details
the procedure. The variables at the top of each column (without

subscripts

) have the same meaning as above.
That is to say,

r

is used for the

sequence

of remainders and

q

for the corresponding sequence of

quotients

. The entries in the

k

and

l

columns are obtained by multiplying the current values for

k

and

l

by the

q

in this row, and subtracting the results from the

k

and

l

in the previous row.

r

q

k

l

756

1

0

595

1

0

1

161

3

1

-

1

112

1

-

3

4

49

2

4

-

5

14

3

-

11

14

7

2

37

-

47

0

Thus,

g

⁢

c

⁢

d

⁢

(

756

,

595

)

=

7

and

37

⋅

756

-

47

⋅

595

=

7

.

Euclid’s algorithm was first described in his classic work

Elements

(see

propositions

VII 1 and VII 2),
which also

contained

procedures
for geometrical constructions. These are the first known
formally described algorithms. Prior to this, informally defined algorithms were in common use to
perform various computations, but

Elements

contained the first attempt to rigorously
describe a procedure and explain why its results are

admissible

. Euclid’s algorithm for greatest
common divisor is still commonly used today; since

Elements

was published in the fourth
century BC, this algorithm has been in use for nearly 2400 years!

Title

Euclid’s algorithm

Canonical name

EuclidsAlgorithm

Date of creation

2013-03-22 12:00:04

Last modified on

2013-03-22 12:00:04

Owner

rmilson (146)

Last modified by

rmilson (146)

Numerical id

21

Author

rmilson (146)

Entry type

Algorithm

Classification

msc 11A05

Synonym

Euclidean algorithm

Related topic

BezoutsLemma

Related topic

EuclideanRing

Generated on Fri Feb 9 15:09:46 2018 by

LaTeXML