Euclidean Algorithm Calculator

Compute GCD via the Euclidean algorithm with step-by-step division, extended Euclidean algorithm, Bézout coefficients, LCM, presets, steps table, and visual representation.

GCD
21
Greatest common divisor of 252 and 105 found in 3 steps
LCM
1,260
Least common multiple = |a × b| / GCD = 252 × 105 / 21
Coprime?
No
They share the common factor 21
Steps
3
Number of division steps in the Euclidean algorithm
Bézout x
-2
Coefficient x such that 252×(-2) + 105×(5) = 21
Bézout y
5
Coefficient y in the Bézout identity ax + by = GCD(a, b)
a / GCD
12
252 reduced by the GCD
b / GCD
5
105 reduced by the GCD

Size Comparison

a = 252
b = 105
GCD = 21

Division Steps

StepDividendDivisorQuotientRemainderExpression
1252105242252 = 2 × 105 + 42
210542221105 = 2 × 42 + 21
342212042 = 2 × 21 + 0

Bézout Identity Verification

252 × (-2) + 105 × (5) = 21✓ Verified
GCD Reference Table
abGCDLCMStepsCoprime?
1284242No
481861443No
10075253002No
252105211,2603No
10714622123,5623No
171312213Yes
14489112,81610Yes
3456216043217,2804No
Planning notes, formulas, and examples

About the Euclidean Algorithm Calculator

The **Euclidean Algorithm Calculator** computes the greatest common divisor (GCD) of two integers using the classical Euclidean algorithm, one of the oldest known algorithms in mathematics — dating back to Euclid's *Elements* around 300 BC. Enter any two positive integers and see the step-by-step division process, the quotient and remainder at each stage, and the final GCD.

Beyond the basic algorithm, this page also performs the **extended Euclidean algorithm**, which finds integers x and y (Bézout coefficients) such that ax + by = gcd(a, b). These coefficients are essential for computing modular inverses, solving linear Diophantine equations, and many cryptographic algorithms including RSA key generation.

The calculator displays the LCM (least common multiple) derived from the GCD using the identity LCM(a, b) = |a × b| / GCD(a, b). You can also explore co-primality — whether the two numbers share no common factor other than 1. A detailed steps table shows every division with the dividend, divisor, quotient, and remainder. The back-substitution table then traces how the Bézout coefficients are built from these remainders.

Preset buttons load classic examples like GCD(252, 105) = 21 and larger cases for practice. A visual bar representation shows the relative sizes of the two numbers and their GCD. Whether you are learning number theory, studying for a math competition, or implementing cryptographic algorithms, the output keeps the division steps and the Bézout back-substitution in the same view.

When This Page Helps

Use this page when you need more than the final gcd. It keeps the quotient-remainder chain, Bézout coefficients, and derived LCM together so you can follow the algorithm from the first division through the final back-substitution.

How to Use the Inputs

  1. Enter two positive integers in the input fields.
  2. Click a preset button to load a classic GCD example.
  3. Review the output cards for GCD, LCM, and Bézout coefficients.
  4. Examine the steps table for the full division chain.
  5. Check the back-substitution table for extended algorithm details.
  6. Use the visual bars to see relative sizes of the inputs and GCD.
Formula used
GCD(a, b): Divide a by b to get remainder r. Replace a with b, b with r. Repeat until r = 0. The last non-zero remainder is the GCD. Extended: find x, y such that ax + by = GCD(a, b).

Example Calculation

Result: 2×105 + 42

GCD(252, 105): 252 = 2×105 + 42, then 105 = 2×42 + 21, then 42 = 2×21 + 0. GCD = 21. Extended: 21 = 1×252 + (−2)×105, so x = 1, y = −2.

Tips & Best Practices

  • Check that all inputs use the same scale and assumptions before trusting the result.
  • Compare the answer with the worked example or a rough estimate to catch entry mistakes.

How the Euclidean Algorithm Works

The algorithm is based on the identity GCD(a, b) = GCD(b, a mod b). Starting with two positive integers, you divide the larger by the smaller, note the remainder, and repeat with the divisor and remainder until the remainder is zero. The last non-zero remainder is the GCD. For 252 and 105: 252 = 2×105 + 42, then 105 = 2×42 + 21, then 42 = 2×21 + 0. The GCD is 21. The algorithm terminates in O(log min(a, b)) steps — remarkably efficient even for numbers with hundreds of digits.

The Extended Algorithm and Bézout's Identity

Bézout's identity guarantees that for any integers a and b, there exist integers x and y such that ax + by = GCD(a, b). The extended Euclidean algorithm finds x and y by back-substituting through the division steps. From our example: 21 = 105 − 2×42 = 105 − 2×(252 − 2×105) = 3×105 − 2×252, attempting... actually 21 = 1×252 + (−2)×105. This result has profound applications: computing modular inverses (if GCD(a, m) = 1, then x from ax + my = 1 is a⁻¹ mod m), solving linear Diophantine equations, and establishing key relationships in number theory.

Applications in Cryptography and Computer Science

The extended Euclidean algorithm is at the heart of RSA encryption: to compute the private key d, you need the modular inverse of e modulo φ(n), which is exactly what the extended algorithm provides. Diffie-Hellman key exchange, elliptic-curve cryptography, and Chinese Remainder Theorem implementations all rely on modular inverses as well. Beyond cryptography, the algorithm appears in fraction simplification (divide numerator and denominator by their GCD), continued-fraction expansion, lattice reduction, and even music theory (computing rhythmic patterns based on GCD relationships). Its O(log n) efficiency makes it one of the earliest and most ubiquitous algorithms in computer science.

Sources & Methodology

Last updated:

Frequently Asked Questions

  • An ancient method for finding the greatest common divisor of two integers by repeatedly dividing the larger by the smaller and taking the remainder until the remainder is zero.