Enter Two Integers
Positive, negative, zero, and very large whole numbers are supported by the main Euclidean and extended calculations.
Recent Calculation History
Stored only in this browser.
Example Data Table
| First number | Second number | GCD | LCM | Relationship |
|---|---|---|---|---|
| 48 | 18 | 6 | 144 | Shared factors |
| 100 | 25 | 25 | 100 | 25 divides 100 |
| 17 | 13 | 1 | 221 | Coprime |
| 0 | 15 | 15 | 0 | Zero case |
| -24 | 36 | 12 | 72 | Signs ignored for GCD |
| 270 | 192 | 6 | 8,640 | Multiple Euclidean steps |
Formula Used
Euclidean recurrence
gcd(a, b) = gcd(b, a mod b)Continue until the remainder becomes zero. The last nonzero divisor is the GCD.
GCD and LCM identity
gcd(a, b) × lcm(a, b) = |a × b|
Bézout identity
ax + by = gcd(a, b)The extended Euclidean algorithm finds one integer pair x and y.
Zero rules
gcd(a, 0) = |a| for nonzero a. The value gcd(0, 0) is undefined.
How to Use This Calculator
- Enter the first whole number. A leading plus or minus sign is allowed.
- Enter the second whole number. Do not enter commas, spaces, decimals, or exponent notation.
- Select one detailed method or choose all supported methods.
- Choose whether to list divisors, verify the GCD-LCM identity, or show the extended table.
- Press Calculate GCD. The main result appears above the form.
- Review the Euclidean steps, prime factors, coefficients, ratio, fraction, and relationship checks.
- Copy the result, export CSV, create a PDF, print the page, or copy a shareable link.
Understanding the Greatest Common Divisor
The greatest common divisor is the largest positive integer that divides two integers without a remainder. It is also called the greatest common factor or highest common factor. These names describe the same number. The calculator uses absolute values for the main GCD, so negative signs do not make the result negative.
Why the Euclidean algorithm matters
Listing every factor can work for small values. It becomes slow for large values. The Euclidean algorithm is usually much faster. It replaces a pair of numbers with the smaller number and the remainder. Each replacement keeps the same GCD. The process ends when a remainder becomes zero.
For 48 and 18, divide 48 by 18. The remainder is 12. Next, divide 18 by 12. The remainder is 6. Finally, divide 12 by 6. The remainder is zero. Therefore, the last nonzero divisor is 6.
Prime factors and common factors
Prime factorization gives another clear method. Write each number as a product of primes. Keep only the primes shared by both numbers. Use the smaller exponent for every shared prime. Multiplying those shared prime powers gives the GCD.
Every positive common divisor must divide the GCD. This fact makes the common factor list easy to understand. Once the GCD is known, its positive divisors are exactly the positive numbers that divide both inputs.
Reduced ratios and fractions
A ratio can be reduced by dividing both terms by their GCD. The same rule reduces a fraction. For example, 48:18 becomes 8:3 after division by 6. The fraction 48/18 also becomes 8/3. A GCD of one means the ratio or fraction is already in lowest terms.
LCM and verification
The least common multiple is the smallest nonnegative number divisible by both inputs. For nonzero integers, the product of the GCD and LCM equals the absolute product of the inputs. This calculator displays both sides of that identity, which provides a useful arithmetic check.
Bézout coefficients
The extended Euclidean algorithm does more than find a divisor. It also finds integers x and y that satisfy ax + by = gcd(a, b). These coefficients support modular inverses, congruences, cryptography, and linear Diophantine equations. When the GCD is one, a modular inverse may exist.
Special values
Zero needs careful treatment. The GCD of zero and a nonzero integer is the absolute value of the nonzero integer. The LCM in that case is zero. The GCD of zero and zero is not defined because no greatest positive common divisor exists. The calculator reports this case clearly.
Choosing a method
Use the Euclidean algorithm for fast general work. Use prime factorization when learning factor structure. Use common factors for small classroom examples. Use the binary method when studying low-level integer algorithms. Use repeated subtraction for intuition, not speed. Use the extended method when coefficients or modular arithmetic are required.
Frequently Asked Questions
What is the GCD of two numbers?
It is the largest positive integer that divides both numbers exactly. GCD, GCF, and HCF usually mean the same thing.
Can the calculator use negative numbers?
Yes. It uses absolute values when finding the GCD, so the main result is always nonnegative.
What happens when one input is zero?
The GCD equals the absolute value of the nonzero input. The LCM is zero.
Why is GCD(0, 0) undefined?
Every positive integer divides both zeros. Therefore, no greatest positive common divisor exists.
What does coprime mean?
Two integers are coprime when their GCD is one. They do not share any prime factor.
How is the LCM calculated?
For nonzero inputs, LCM equals the absolute product divided by the GCD. The implementation divides before multiplying to reduce intermediate size.
What are Bézout coefficients?
They are integers x and y satisfying ax + by = gcd(a, b). The extended Euclidean algorithm finds them.
When does a modular inverse exist?
The first number has an inverse modulo the second when their GCD is one and the modulus is greater than one.
Why can prime factorization be unavailable?
Factoring large integers may require heavy computation. The page limits factorization while keeping the Euclidean result exact.
Why is repeated subtraction limited?
Repeated subtraction can require many iterations. The Euclidean algorithm reaches the same answer more efficiently.
Can I enter very large integers?
Yes. Core decimal arithmetic, Euclidean steps, LCM, ratios, and Bézout coefficients use string-based arbitrary-length operations.
Does the calculator accept decimals?
No. GCD is defined here for integers, so decimal and scientific notation inputs are rejected.
Where is calculation history stored?
Recent entries are stored in local browser storage. They are not sent to a separate history service.
Can I share a calculation?
Yes. The share button creates a link containing the inputs and selected display settings.