Euclid's method for finding the greatest common divisor (GCD) of two starting lengths BA and DC, both defined to be multiples of a common "unit" length. The length DC being shorter, it is used to "measure" BA, but only once because the remainder EA is less than DC. EA now measures (twice) the shorter length DC, with remainder FC shorter than EA. Then FC measures (three times) length EA. Because there is no remainder, the process ends with FC being the GCD. On the right Nicomachus
's example with numbers 49 and 21 resulting in their GCD of 7 (derived from Heath 1908:300).
, the Euclidean algorithm
, or Euclid's algorithm
, is an efficient method for computing the greatest common divisor
(GCD) of two integers (numbers), the largest number that divides them both without a remainder
. It is named after the ancient Greek mathematician Euclid
, who first described it in his Elements
(c. 300 BC).
It is an example of an algorithm
, a step-by-step procedure for performing a calculation according to well-defined rules,
and is one of the oldest algorithms in common use. It can be used to reduce fractions
to their simplest form
, and is a part of many other number-theoretic and cryptographic calculations.
The Euclidean algorithm is based on the principle that the greatest common divisor of two numbers does not change if the larger number is replaced by its difference with the smaller number. For example, 21 is the GCD of 252 and 105 (as 252 = 21 × 12 and 105 = 21 × 5), and the same number 21 is also the GCD of 105 and 252 − 105 = 147. Since this replacement reduces the larger of the two numbers, repeating this process gives successively smaller pairs of numbers until the two numbers become equal. When that occurs, they are the GCD of the original two numbers. By reversing the steps
or using the extended Euclidean algorithm
, the GCD can be expressed as a linear combination
of the two original numbers, that is the sum of the two numbers, each multiplied by an integer
(for example, 21 = 5 × 105 + (−2) × 252).
The fact that the GCD can always be expressed in this way is known as Bézout's identity
. (Full article...