Correctness
Why does this work?
Termination is trivial, because the second argument is always decreasing by at least 1 and the process terminates when it reaches zero.
Need to show
.
First, note that any number that divides both
a
and
b
also divides
.
Then, note that any number that divides both
b
and
also divides
a
.
This implies that the
largest
such divisor of one pair must be equal to the largest of the other pair.
Next:
Efficiency Analysis
Up:
GREATEST COMMON DIVISOR
Previous:
Example