GCD and LCM Calculator
The greatest common divisor (GCD) and the least common multiple (LCM) are two core number-theory tools for working with integers. You’ll use the GCD when you want the biggest “shared factor” (for example, to reduce fractions), and the LCM when you want the smallest “shared multiple” (for example, to align repeating schedules or find a common denominator). This calculator accepts a comma-separated list of integers such as 12, 18, 30 and returns both the overall GCD and the overall LCM.
Introduction: What this calculator computes
- GCD of many numbers: the largest positive integer that divides every input number.
- LCM of many numbers: the smallest positive integer that is a multiple of every input number (when defined).
Key formulas
For two nonzero integers a and b, the GCD is commonly computed using the Euclidean algorithm, and the LCM is linked to the GCD by a simple identity:
Relationship between GCD and LCM (two numbers):
Extending to multiple numbers: the calculator reduces a list step-by-step (associatively):
gcd(a, b, c) = gcd(gcd(a, b), c)lcm(a, b, c) = lcm(lcm(a, b), c)
How to interpret the results
- If the GCD is 1, the numbers are coprime as a set (they share no common factor greater than 1). This is a common check in simplifying ratios or confirming relative primality.
- The LCM is the smallest “alignment point” where all numbers divide evenly. It’s useful for common denominators (fractions) and repeating-cycle problems (timers, schedules, patterns).
- For inputs that include negative numbers, GCD/LCM are typically reported as positive values based on absolute magnitude.
Worked example (multiple numbers)
Input: 12, 18, 30
Step 1 (GCD):
gcd(12, 18) = 6gcd(6, 30) = 6
Result: GCD = 6
Step 2 (LCM):
lcm(12, 18) = |12×18| / gcd(12,18) = 216 / 6 = 36lcm(36, 30) = |36×30| / gcd(36,30)gcd(36, 30) = 6, solcm = 1080 / 6 = 180
Result: LCM = 180
GCD vs LCM: quick comparison
| Concept | Definition (informal) | Common use | Example (12 and 18) |
|---|---|---|---|
| GCD | Largest shared factor | Simplify fractions/ratios; check coprime | gcd(12,18)=6 |
| LCM | Smallest shared multiple | Common denominators; align repeating cycles | lcm(12,18)=36 |
Limitations and assumptions
- Integers only: Inputs should be whole numbers. Decimals or fractions should be converted to integers first (e.g., scale by a common factor).
- Zero handling:
gcd(0, n) = |n|. For LCM, many definitions setlcm(0, n) = 0; if any input is 0, the overall LCM is typically reported as 0. - Sign handling: Results are usually returned as positive values using absolute values.
- Large outputs: LCM can grow very quickly for multiple inputs; extremely large integers may overflow some JavaScript number handling unless big-integer arithmetic is used.
More examples to try
8, 20→ GCD 4, LCM 407, 9, 28→ GCD 1, LCM 252-6, 15→ GCD 3, LCM 300, 12, 18→ GCD 6, LCM 0 (by common convention)
How to use this calculator
- Enter Numbers (comma-separated) using the unit or time period shown by the field.
- Run the calculation and compare the output with a second scenario before acting on it.
Arcade Mini-Game: GL GCD and LCM Calculator Calibration Run
Use this quick arcade run to practice separating useful scenario inputs from common planning mistakes before you rely on the calculator output.
Start the game, then use your pointer or arrow keys to catch useful inputs and avoid bad assumptions.
