Formula and example
How it is calculated
GCD(a,b) = GCD(b,a mod b). For a,b ≠ 0, LCM(a,b) = |a·b|/GCD(a,b).
Worked example
For 12, 18 and 30, the GCD is 6 and the LCM is 180. Prime factors: 12 = 2²·3, 18 = 2·3² and 30 = 2·3·5.
Things to check
- Signs do not change the GCD or LCM. The number 1 has no prime factors; 0 has no prime factorisation.
- The LCM is returned as an exact integer, even beyond the usual floating-point precision.
Frequently asked questions
What happens with a zero?
GCD(a,0) is |a|. In this tool, GCD(0,0) and any LCM with a zero input are defined as 0.