Extended Euclidean Algorithm Calculator
Find GCD(a, b) and the Bézout coefficients x and y with a·x + b·y = GCD, with every division step listed. Euclid: GCD(a, b) = GCD(b, a mod b). Example: with first number a 240, second number b 46, the result is GCD = 2.
Last updated · By S. Dilshan · Runs in your browser, nothing is uploaded
Step-by-Step Solution
How do you use the Extended Euclidean Algorithm Calculator?
Enter two positive whole numbers. The calculator runs the Euclidean algorithm, lists every division with remainder, and tracks coefficients to express the greatest common divisor as a combination of the two numbers (Bézout’s identity).
What formula does the Extended Euclidean Algorithm Calculator use?
Euclid: GCD(a, b) = GCD(b, a mod b). The extended version also maintains coefficients so that every remainder rᵢ equals a·sᵢ + b·tᵢ. When the remainder reaches 0, the previous remainder is the GCD and its coefficients are Bézout’s x and y.
Worked example: First number a 240, Second number b 46
For 240 and 46: 240 = 5 × 46 + 10, 46 = 4 × 10 + 6, 10 = 1 × 6 + 4, 6 = 1 × 4 + 2 and 4 = 2 × 2. The GCD is 2, and 240 × (−9) + 46 × 47 = 2.
With the default values the calculator returns GCD = 2; Bézout coefficients (x, y) = x = -9, y = 47; Identity = 240 × -9 + 46 × 47 = 2; LCM = 5520.
Where Is This Calculation Used?
The extended algorithm gives modular inverses, solves linear Diophantine equations ax + by = c (solvable exactly when GCD(a, b) divides c) and underlies the Chinese remainder theorem. It is also the standard method for computing RSA private keys.
The algorithm is fast: by Lamé’s theorem the number of division steps never exceeds five times the number of digits of the smaller number, and the worst case occurs for consecutive Fibonacci numbers. That keeps it practical for the 300-digit numbers used in RSA. The identity ax + by = gcd(a, b) also shows that ax + by = c has integer solutions exactly when gcd(a, b) divides c.
What are the most common mistakes with the Extended Euclidean Algorithm Calculator?
- Stopping at the last non-zero remainder before recording coefficients.
- Expecting unique Bézout coefficients; any (x + k·b/g, y − k·a/g) also works.
- Using negative numbers without taking absolute values first.
What Is the Tested Example for the Default Values?
This example is computed by the same code that powers the calculator above, so you can compare it with your own numbers or a textbook answer.
| Input: First number a | 240 |
|---|---|
| Input: Second number b | 46 |
| GCD | 2 |
| Bézout coefficients (x, y) | x = -9, y = 47 |
| Identity | 240 × -9 + 46 × 47 = 2 |
| LCM | 5520 |
Where Can You Verify These Formulas?
The definitions and formulas on this page follow standard references. Check them against these sources:
Built and maintained by S. Dilshan. Found a mistake? Email [email protected] with the page address.
Frequently Asked Questions
What is Bézout’s identity?
For integers a and b there exist integers x and y with a·x + b·y = GCD(a, b).
Are the Bézout coefficients unique?
No. Adding b/GCD to x and subtracting a/GCD from y gives another valid pair.
How is the extended Euclidean algorithm used?
To find modular inverses, solve linear Diophantine equations and compute RSA private keys.