Euclidean Algorithm Calculator
Find the Greatest Common Divisor (GCD) with detailed step-by-step solutions
Final Result
GCD(a, b) = ?
Step-by-Step Solution
Extended Euclidean Algorithm
The equation gcd(a, b) = a·x + b·y has solution:
Geometric Visualization
The GCD represents the largest square tile that can exactly cover a rectangle of size a×b without cutting.
Understanding the Euclidean Algorithm
The Euclidean algorithm is one of the oldest known algorithms, dating back to 300 BC. It efficiently finds the greatest common divisor (GCD) of two integers by repeatedly applying the division algorithm.
The Basic Principle
The algorithm is based on this key observation:
gcd(a, b) = gcd(b, a mod b)
Where "a mod b" is the remainder when a is divided by b. The process continues until the remainder is zero, at which point the non-zero remainder is the GCD.
Why It Works
Any common divisor of a and b must also divide (a mod b), so the set of common divisors remains unchanged at each step. The last non-zero remainder divides all previous remainders and thus both original numbers.
Time Complexity
The algorithm runs in O(log min(a,b)) time, making it extremely efficient even for very large numbers.
Applications
- Simplifying fractions
- Cryptography (RSA algorithm)
- Diophantine equations
Extended Euclidean Algorithm
The extended version finds integers x and y (called Bézout coefficients) such that:
a·x + b·y = gcd(a, b)
This is particularly useful in modular arithmetic and solving linear Diophantine equations.
Frequently Asked Questions
What is the Euclidean algorithm used for?
The Euclidean algorithm is primarily used to find the greatest common divisor (GCD) of two integers. This has applications in simplifying fractions, number theory, cryptography (especially RSA algorithm), and solving Diophantine equations.
How does the Euclidean algorithm work?
The algorithm works by repeatedly dividing the larger number by the smaller number and replacing the larger number with the remainder until the remainder is zero. The last non-zero remainder is the GCD. Our calculator shows each step of this process.
What's the difference between basic and extended Euclidean algorithm?
The basic version just finds the GCD, while the extended version also finds Bézout coefficients (x and y) that satisfy the equation ax + by = gcd(a,b). These coefficients are useful for modular inverses and solving linear equations.
Can the Euclidean algorithm handle negative numbers?
Yes, but the GCD is always positive. The algorithm works with negative numbers by simply taking their absolute values. Our calculator automatically handles this conversion.
Why is the Euclidean algorithm efficient?
The algorithm's efficiency comes from the fact that the numbers decrease rapidly with each step (at least by a factor of the golden ratio). This gives it logarithmic time complexity O(log min(a,b)), making it practical even for very large numbers (hundreds of digits).
Practice Problems
Beginner
- gcd(14, 21)
- gcd(30, 45)
- gcd(17, 23)
Advanced
- gcd(123456, 654321)
- gcd(1001, 1331)
- gcd(4181, 6765)
Challenge: For the advanced problems, try solving them manually first before checking with the calculator. Notice how few steps the algorithm needs even for large numbers.