Overview
The Euclidean Algorithm repeatedly replaces (a, b) with (b, a mod b) until the remainder is zero. The last nonzero value is the greatest common divisor.
Computes the greatest common divisor of two integers by repeatedly taking remainders.
Compact metadata for implementation and discovery.
The Euclidean Algorithm repeatedly replaces (a, b) with (b, a mod b) until the remainder is zero. The last nonzero value is the greatest common divisor.
Quick facts
Runtime and memory behavior at a glance.
Best
O(1)
Average
O(log min(a, b))
Worst
O(log min(a, b))
Space
O(1)
gcd(a,b) = gcd(b, a mod b)Reduces the problem until the remainder is zero.
Show repeatedly replacing the larger value with a remainder on a small greatest common divisor example.
The algorithm works because replacing a number by its remainder preserves the common divisors of the pair.
What each reference supports for this entry.
Reference for Euclidean Algorithm's arithmetic operations, modular arithmetic, multiplication, division, or number-theoretic implementation details.
Open sourceTextbook support for Euclidean Algorithm's algorithm family, complexity framing, and standard implementation concepts.
Open sourceGood next jumps from the relationship graph, ranked for useful discovery.
Cryptography · Core
Fermat testing may use gcd to detect bases that already share a factor with n.
Compare with thisCryptography · Core
Pollard's rho repeatedly uses gcd computations to expose factors.
Compare with thisCryptography · Foundation
GCD checks often appear with modular arithmetic routines.
Compare with thisNumerical Methods · Foundation
Extended Euclid augments the remainder sequence with coefficient tracking.
Compare with thisExtended Euclid augments the remainder sequence with coefficient tracking.
Binary GCD is a specialized gcd method that replaces division with shifts and subtraction.
GCD checks often appear with modular arithmetic routines.