GCD Calculator (Euclidean Algorithm)
Returns the greatest common divisor of two integers through repeated remainder division, the Euclidean algorithm. Signs are ignored and decimals truncated.
MDC(a,b)
—
Euclidean algorithm for the greatest common divisor
The Euclidean algorithm finds gcd(a, b) by applying the identity gcd(a, b) = gcd(b, a mod b) over and over until b = 0. Whatever value of a is left at that point is the GCD. You'll find it in Euclid's Elements (~300 BC), Book VII, which makes it one of the oldest non-trivial algorithms people still run every day. Its complexity is O(log min(a, b)), and Lamé's theorem tells us the slowest case happens with consecutive Fibonacci numbers as inputs.
Here's a run: gcd(48, 18) → gcd(18, 12) → gcd(12, 6) → gcd(6, 0) = 6. There's also the extended Euclidean algorithm, which hands back Bézout coefficients x, y satisfying a·x + b·y = gcd(a, b). That's the route used to compute modular inverses.
Applications
- Cryptography: the modular inverse behind RSA key generation and ECDSA comes from extended Euclid.
- Simplifying fractions: divide both parts of
a/bbygcd(a, b)and you land on the lowest terms. - Diophantine equations:
ax + by = conly has integer solutions whengcd(a, b)dividesc. - Competitive programming: a go-to for number-theory problems and reductions.
FAQ
What is gcd(a, 0)? By convention it's gcd(a, 0) = |a|, and that serves as the base case of the recursion.
Does it work with negative numbers? Yes. Most implementations take absolute values up front, because the GCD is defined to be non-negative.
What about gcd of more than two numbers? Lean on associativity and chain them: gcd(a, b, c) = gcd(gcd(a, b), c).
Related Tools
GCD Calculator
Calculate the Greatest Common Divisor (GCD) of two or more numbers using the Euclidean algorithm. Instant result.
GCD with Bezout Coefficients
Compute gcd(a,b) and Bezout coefficients x,y where a·x + b·y = gcd.
GCD of Multiple Numbers Calculator
Calculate the GCD (greatest common divisor) of a list of integers all at once. Enter the values separated by commas and see the result instantly.
Prime Factorization Calculator
Splits a whole number of 2 or more into its prime powers by trial division: type 360 and read back 2^3 · 3^2 · 5, the unique decomposition.
Paris RATP Bus Comparison
Estimates RATP Paris bus travel time at 14 km/h, useful to compare with Brazilian buses.
Cohen's h (Effect Size for Proportions)
Computes Cohen's h, the effect-size measure for the difference between two proportions. Comparing proportions directly is misleading, because the same arithmetic difference weighs differently near the middle (0.5) and near the ends (0 or 1). Cohen's h fixes this by applying the arcsine transformation, which stabilizes the variance, before measuring the distance. Usual convention: 0.2 is small, 0.5 medium and 0.8 large. Enter the two proportions (between 0 and 1).
The results provided by this tool are for general informational and educational purposes only and do not constitute professional, financial, medical, legal, tax or accounting advice. Always confirm important decisions with a qualified professional and official sources.