A simple description of the Euclidean algorithm and its respective implementation code in C++ and Java - Full-text Search Blog

by minidxer on 2008-01-29 00:32:28

Description of the Euclidean Algorithm: The Euclidean algorithm, also known as the method of successive division, is used to calculate the greatest common divisor (GCD) of two integers $a$ and $b$. Its computational principle relies on the following theorem:

**Theorem:** $ \text{gcd}(a, b) = \text{gcd}(b, a \mod b) $

**Proof:**

Let $a$ be expressed as $a = kb + r$, where $r = a \mod b$.

1. Suppose $d$ is a common divisor of $a$ and $b$. Then we have $d | a$ and $d | b$. Since $r = a - kb$, it follows that $d | r$. Therefore, $d$ is also a common divisor of $b$ and $a \mod b$.

2. Conversely, suppose $d$ is a common divisor of $b$ and $a \mod b$. Then $d | b$ and $d | r$. Since $a = kb + r$, it follows that $d | a$. Thus, $d$ is also a common divisor of $a$ and $b$.

From the above reasoning, the set of common divisors of $(a, b)$ is the same as the set of common divisors of $(b, a \mod b)$. Consequently, their greatest common divisors must also be equal. This completes the proof.