Compute the greatest common divisor (GCD) for any set of integers using the classical Euclidean algorithm. Paste numbers (comma, space, or line separated) and get detailed step-by-step division, least common multiple (LCM), and coprimality check.
The Greatest Common Factor (GCF), also known as the Greatest Common Divisor (GCD), is the largest positive integer that divides each of the given integers without leaving a remainder. It is a fundamental concept in number theory, essential for simplifying fractions, solving Diophantine equations, and understanding modular arithmetic. The Euclidean algorithm, first described by Euclid around 300 BCE, provides an efficient method to compute the GCD without requiring prime factorization.
For integers a and b, GCD(a, b) = GCD(b, a mod b) until remainder becomes zero.
The last non‑zero remainder is the GCD.
The Euclidean algorithm extends beyond computing GCD. The Extended Euclidean Algorithm finds integers x and y such that:
ax + by = gcd(a, b)
This equation, known as Bézout's identity, forms the mathematical foundation for modular inverses in cryptography. In the RSA encryption system, finding integers satisfying this equation is essential for key generation and digital signature verification.
In modern public-key cryptography, particularly RSA (Rivest-Shamir-Adleman), the Euclidean algorithm is crucial for:
Let's examine how the Euclidean algorithm is used in RSA:
Step 1: Choose two prime numbers
Let p = 61, q = 53
Step 2: Compute n and φ(n)
n = p × q = 61 × 53 = 3233
φ(n) = (p-1)(q-1) = 60 × 52 = 3120
Step 3: Choose public exponent e
Select e = 17 (must be coprime with 3120)
Check: gcd(17, 3120) = 1 ✓
Step 4: Compute private key d
Using the Extended Euclidean Algorithm, find d such that:
17d ≡ 1 (mod 3120)
The solution is d = 2753
The Euclidean algorithm ensures that the modular inverse exists and can be computed efficiently, making secure communication possible.
The algorithm relies on the property: any common divisor of a and b also divides their difference (a – b). By repeatedly replacing the larger number with the remainder of division, the numbers shrink exponentially, guaranteeing a fast termination (O(log min(a,b)) steps). For more than two numbers, the GCD is associative: GCD(a, b, c) = GCD(GCD(a, b), c). Our calculator implements the iterative Euclidean algorithm and displays every step, making the process transparent for learners.
Historically, Euclid’s Elements (Book VII, Proposition 2) provided the first known description. Today, it remains the backbone of cryptographic systems like RSA, where the GCD is used to compute modular inverses.
Euclidean algorithm:
48 ÷ 18 = 2 remainder 12 → GCD(48,18) = GCD(18,12)
18 ÷ 12 = 1 remainder 6 → GCD(18,12) = GCD(12,6)
12 ÷ 6 = 2 remainder 0 → GCD = 6.
Therefore, GCF(48,18) = 6. The LCM is (48×18)/6 = 144.
Our tool displays such steps automatically for any set of numbers.
The Euclidean algorithm has time complexity O(log min(a,b)), making it one of the oldest algorithms still in widespread use. This logarithmic complexity means that even for numbers with thousands of digits (common in cryptography), the algorithm terminates quickly.
For computer implementations, the binary GCD algorithm uses bitwise operations instead of division, making it more efficient on modern hardware:
| Numbers | GCF | LCM | Coprime? | Euclidean steps count |
|---|---|---|---|---|
| (12, 18) | 6 | 36 | No | 2 |
| (24, 36, 48) | 12 | 144 | No | 2 iterations |
| (17, 19) | 1 | 323 | Yes | 1 |
| (100, 25, 50) | 25 | 100 | No | 2 |
| (81, 27) | 27 | 81 | No | 1 |
| (144, 96, 72) | 24 | 288 | No | 3 |