LCM & GCF Calculator
Find the Least Common Multiple (LCM) and Greatest Common Factor (GCF) of two whole numbers.
How it's calculated
The GCF is found using the Euclidean algorithm: repeatedly divide the larger number by the smaller and replace the larger with the remainder, until the remainder is zero — the last non-zero remainder is the GCF.
The LCM is then derived from the GCF using the identity LCM(a, b) = (a × b) ÷ GCF(a, b), which is faster than listing multiples of each number.
Worked example
For 12 and 18: the GCF is 6 (the largest number dividing both evenly), and the LCM is (12 × 18) ÷ 6 = 36.
What the tool accepts
- Two numbers only. Each must be greater than zero, so 0 or negative entries give an error.
- Decimals are rounded to the nearest whole number before anything is calculated. Typing 12.6 is treated as 13, and no warning is shown.
- Both answers appear together: the greatest common factor and the least common multiple.
More worked examples
8 and 12 give a GCF of 4 and an LCM of 24. 21 and 6 give 3 and 42, since 21 × 6 = 126 and 126 ÷ 3 = 42.
7 and 13 share no factor except 1, so the GCF is 1 and the LCM is their product, 91. When one number divides the other, as with 4 and 20, the GCF is the smaller number (4) and the LCM is the larger one (20). Two equal numbers such as 9 and 9 return 9 and 9.
Three numbers and large inputs
For three numbers, run the tool twice: find the LCM of the first pair, then use that answer with the third number. The same chaining works for the GCF.
Very large inputs are handled with ordinary JavaScript numbers. The LCM of 123456789012 and 987654321098 is displayed in exponent form (about 6.1 × 10²²), and values that large are not guaranteed to be exact to the last digit.
Examples and input rules
12 and 18 have a greatest common factor of 6 and a least common multiple of 36. 17 and 5 share no factor, so the GCF is 1 and the LCM is their product, 85.
The tool takes exactly two numbers. Zero and negative numbers are rejected with "Please enter two positive whole numbers." A decimal is not rejected but rounded first, so 4.5 and 6 are treated as 5 and 6 and give a GCF of 1 and an LCM of 30, which is easy to miss if you did not mean to round.
Frequently asked questions
What's the difference between LCM and GCF?
The GCF is the largest number that divides both inputs evenly. The LCM is the smallest number that both inputs divide into evenly. They answer opposite questions.
Where is this used in real life?
GCF is used to simplify fractions to lowest terms; LCM is used to find a common denominator when adding fractions, or to schedule events that repeat at different intervals.
What happens if I enter 12.6 and 18?
The first number is rounded to 13, so the tool returns a GCF of 1 and an LCM of 234, the answers for 13 and 18.
Can I find the LCM of three numbers?
Yes, in two passes. Find the LCM of the first two, then enter that result and the third number.
What does a GCF of 1 tell me?
The two numbers have no common factor other than 1, so they are coprime. Their LCM equals their product.