Math
GCD & LCM Calculator
Enter two positive integers to see their GCD, LCM and how the two relate.
The link carries your figures, so it reopens on exactly these numbers.
The formula
gcd via Euclid: gcd(a, 0) = a, gcd(a, b) = gcd(b, a mod b)
lcm = |a × b| ÷ gcd(a, b)
a × b = gcd(a, b) × lcm(a, b)
Worked example
GCD and LCM of 12 and 18
- gcd(18, 12) → gcd(12, 6) → gcd(6, 0) = 6
- lcm = 12 × 18 ÷ 6 = 36
- 12 × 18 = 216 = 6 × 36 ✓
Where this goes wrong
Confusing GCD with LCM
The GCD is the largest factor they share; the LCM is the smallest number they both divide into. For 12 and 18 the GCD is 6 and the LCM is 36 — not the other way round. If you mix them up, a recipe meant for the smallest common batch uses the largest common portion, and the scaling is wrong.
Questions
- What does coprime mean?
- Two numbers are coprime when their only shared factor is 1 — their GCD is 1. 8 and 15 are coprime because 8 = 2³ and 15 = 3 × 5 share no prime factor.
- When do I need the LCM?
- Any time you need to synchronize cycles or find a common denominator. Two traffic lights cycling every 45 and 60 seconds line up every lcm(45, 60) = 180 seconds. Adding 1/4 and 1/6 uses the common denominator lcm(4, 6) = 12.
- Does the GCD × LCM identity always hold?
- Yes, for any two positive integers. a × b = gcd(a, b) × lcm(a, b). It follows from the prime factorization: the GCD takes the minimum exponent of each prime and the LCM takes the maximum, so together they account for the sum — the product.