Euclidean algorithm
The Euclidean algorithm allows us to find the greatest common divisor of any two nonnegative integers.
Contents
[hide]Steps
Start with two nonnegative integers, and
.
- If
, then
.
- Otherwise take the remainder when
is divided by
(
), and find
.
Repeat this until .
Simple Example
To see how it works, just take an example. Say . We have
, so
. Similarly,
, so
. Then
, so
. Thus
.
Usually the Euclidean algorithm is written down just as a chain of divisions:
Linear Representation
An added bonus of the Euclidean algorithm is the "linear representation" of the greatest common divisor. This allows us to write , where
are constants to be determined.
In the example, we can rewrite equation from above as