LCM Calculator
Find the least common multiple (LCM) of two positive integers, with the greatest common divisor shown along the way.
How It's Calculated
Formula
\mathrm{lcm}(A, B) = \frac{|A \times B|}{\gcd(A, B)}The least common multiple (LCM) of two positive integers is the smallest positive number that both A and B divide into evenly. It's found using the greatest common divisor (GCD): the LCM equals A times B, divided by their GCD. This calculator divides before multiplying — computing (A / GCD) x B rather than (A x B) / GCD — so intermediate values stay as small as possible, which matters when working with large inputs. The LCM is not the same thing as the greatest common factor (GCF), even though both are computed from the same GCD: the GCF is the largest number that divides both A and B, while the LCM is the smallest number that both A and B divide into. They measure opposite things — GCF looks for a shared divisor, LCM looks for a shared multiple.
Worked Examples
Find the LCM of 4 and 6
- Euclidean algorithm: gcd(6, 4) -> 6 mod 4 = 2
- gcd(4, 2) -> 4 mod 2 = 0
- Remainder is 0, so GCD = 2
- LCM = (4 / 2) x 6 = 2 x 6
- Result: 12
Find the LCM of two coprime numbers: 9 and 16
- gcd(16, 9) -> 16 mod 9 = 7
- gcd(9, 7) -> 9 mod 7 = 2
- gcd(7, 2) -> 7 mod 2 = 1
- gcd(2, 1) -> 2 mod 1 = 0
- Remainder is 0, so GCD = 1
- LCM = (9 / 1) x 16 = 9 x 16
- Result: 144
Frequently Asked Questions
How is the LCM different from the GCF?
The GCF (greatest common factor) is the largest number that divides evenly into both A and B — it looks for a shared divisor. The LCM (least common multiple) is the smallest number that both A and B divide evenly into — it looks for a shared multiple. They're related (the LCM is computed using the GCD), but they answer opposite questions.
Why divide before multiplying instead of multiplying first?
Computing (A x B) / GCD first multiplies A and B together, which can produce a very large intermediate number even when the final LCM is comparatively small. Computing (A / GCD) x B instead divides first, keeping every intermediate value as small as the final answer, which avoids unnecessary overflow risk for large inputs.
Why are zero, negative numbers, and decimals rejected?
The least common multiple is defined for positive whole numbers. Zero has no well-defined positive multiples in this context, and negative numbers and decimals fall outside the standard integer-LCM definition this calculator uses, so all three are rejected explicitly.