How to find the GCD with the Euclidean algorithm
The Euclidean algorithm computes the greatest common divisor (GCD) of two integers by repeatedly applying the division algorithm until a remainder of zero is reached. It applies to any pair of integers where at least one is non-zero, relying on the identity .
The setup
Identify the two integers and . Ensure . If they are negative, use their absolute values since . If , the GCD is and the process is complete.
The steps
- Divide by to find the integer quotient and remainder , writing it in the form where . 2. If , the algorithm terminates and is the GCD. 3. If , replace with , and replace with . 4. Repeat step 1 with the new values of and .
Checking the result
Verify that your final non-zero remainder cleanly divides both of your starting integers and . To ensure it is the greatest divisor, you can also substitute backwards using the Extended Euclidean Algorithm to express the GCD as a linear combination of and .
Common errors
A frequent error is substituting the quotient instead of the remainder into the next step. Another standard mistake is concluding the algorithm one step early or outputting zero as the GCD; the GCD is always the last non-zero remainder, never zero.
Worked example
Find the GCD of 252 and 105 using the Euclidean algorithm.
Let and . Step 1: Divide 252 by 105. . The remainder is 42. Step 2: Replace with 105 and with 42. Divide 105 by 42. . The remainder is 21. Step 3: Replace with 42 and with 21. Divide 42 by 21. . The remainder is 0, so the algorithm terminates. The last non-zero remainder is 21. Therefore, .
FAQ
Run your own problem
References: Discrete Mathematics and Its Applications by Kenneth H. Rosen · OpenStax Contemporary Mathematics, Number Theory
See also