GCD & LCM Calculator
Calculate the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of two or three numbers.
Did this tool work for you?
How to use this calculator
GCD is found by repeatedly dividing the larger number by the smaller and taking remainders until zero. LCM is derived from GCD.
- 1
Enter two or three positive integers.
- 2
Leave the third number as 0 to calculate for just two numbers.
- 3
The calculator shows GCD and LCM with factor lists for verification.
Frequently asked questions
What happens if I enter a negative number or a decimal?
The calculator works with whole numbers. A negative value is replaced by its absolute value, so −12 and 18 give the same GCD of 6 and LCM of 36 as 12 and 18. A decimal is cut down to its whole part first: 7.9 is treated as 7. Enter integers if you want results for exactly the numbers you have in mind.
Why can I not use 0 for the first or second number?
Zero in either of those fields returns an error. A zero in the third field is different: it means “skip the third number” and the calculator solves for just two. The calculator rejects zero there instead of choosing a convention for it.
How do GCD and LCM relate for two numbers?
Their product equals the product of the two numbers: GCD × LCM = a × b. For 48 and 18 the calculator returns a GCD of 6 and an LCM of 144, and 6 × 144 = 864 = 48 × 18. The calculator relies on this by computing the LCM as a ÷ GCD × b, which avoids building an oversized intermediate product.
What does a GCD of 1 tell me?
The numbers are coprime: they share no divisor other than 1, though neither has to be prime. 17 and 31 give a GCD of 1 and an LCM of 527, which is just their product. 21 and 6 are not coprime; their GCD is 3 and their LCM is 42.
What does the output show with three numbers?
It shows the GCD and LCM of all three, plus GCD(a, b) and GCD(b, c) as stepping stones. For 36, 60 and 84 the overall GCD is 12 and the LCM is 1260. The divisor lists appear only in the two-number mode.
Why is the list of divisors sometimes cut short?
In the two-number mode the divisors of each number are listed in ascending order, up to 200 entries per number followed by an ellipsis. Numbers with that many divisors are rare, so most inputs are shown in full.
Is there a limit on how large the numbers can be?
Yes. Values beyond 9,007,199,254,740,991 (2⁵³ − 1) cannot be held exactly by the browser’s number format, so the calculator returns an error rather than a wrong answer. The LCM itself can exceed that limit for large inputs, in which case its last digits may not be exact.
GCD and LCM calculator — greatest common divisor and least common multiple of two or three integers
Two quantities, one pair of numbers
The greatest common divisor is the largest integer that divides every number you enter. The least common multiple is the smallest positive integer that every number divides. The calculator finds the GCD with the Euclidean algorithm, which repeatedly replaces the pair (a, b) with (b, a mod b) until the remainder is zero, and then derives the LCM from it.
| Numbers | GCD | LCM |
|---|---|---|
| 48 and 18 | 6 | 144 |
| 21 and 6 | 3 | 42 |
| 17 and 31 | 1 | 527 |
| 12, 18 and 30 | 6 | 180 |
| 36, 60 and 84 | 12 | 1260 |
Worked example: tiling a floor
A 48 by 18 rectangle can be covered by identical squares with no cutting. The side of the largest such square is the GCD of 48 and 18, which the calculator gives as 6. Its divisor lists, 1, 2, 3, 4, 6, 8, 12, 16, 24, 48 and 1, 2, 3, 6, 9, 18, show that 1, 2, 3 and 6 are the common divisors, so smaller square tiles also work.
Worked example: repeating schedules
Two events recur every 12 days and every 18 days and happen together today. The next shared day is the LCM, which the calculator returns as 36 for 12 and 18. Adding a third event every 30 days, the three coincide again after 180 days, the LCM of 12, 18 and 30. The GCD of those three numbers is 6, the largest block of days into which all three cycles divide evenly.
Uses in fractions and ratios
To reduce a fraction, divide numerator and denominator by their GCD: 48/18 becomes 8/3 after dividing both by 6. To add fractions with denominators 12 and 18, use their LCM, 36, as the common denominator. Ratios simplify the same way, so a 36:60:84 ratio becomes 3:5:7 when each term is divided by the three-number GCD of 12.
Input rules
Enter whole numbers. Negatives are treated by absolute value and decimals are truncated to their whole part. Leave the third box at 0 to work with only two numbers. Both of the first two numbers must be non-zero, and numbers above 9,007,199,254,740,991 are rejected because they cannot be stored exactly.
Learn more from an authoritative source:
WikipediaFactorial Calculator
Calculate the factorial of any non-negative integer. Also computes permutations (nPr) and combinations (nCr).
Triangle Calculator
Calculate the area, perimeter, angles, and height of a triangle from three sides using Heron's formula.
Circle Calculator
Calculate the area, circumference, diameter, and arc length of a circle from radius, diameter, or circumference.
Pythagorean Theorem Calculator
Calculate any side of a right triangle using the Pythagorean theorem. Solve for hypotenuse or either leg.
Logarithm Calculator
Calculate logarithms in any base — common (base 10), natural (base e), binary (base 2), or custom base.
Exponent Calculator
Calculate any base raised to any power. Handles large exponents, fractional powers (roots), and negative exponents.
Results are estimates for informational purposes only and do not constitute professional financial, medical, legal, or technical advice. Read full disclaimer →