# Greatest common divisor

([itex]1) [/itex]2 | [itex]3 ([/itex]4) | [itex]5 ([/itex]6)

An important technical tool for our study of number theory is the greatest common divisor of two numbers. Here we present an efficient algorithm for computing it:

Definition: gcd
Euclid's GCD algorithm is the function which is given as follows: , and for , where .

This function is a good inductively defined function because by definition, , so the second argument is decreasing in the inductive definition.

The algorithm can be extended to operate on negative integers by simply taking the gcd of the absolute values of its arguments.

In order to justify calling the "greatest common divisor", we should check that gcd(a,b) is a common divisor of a and b and gcd(a,b) is greater than all other common divisors of a and b.