LCM & GCD Calculator
Enter up to N integers to get the least common multiple (LCM) and greatest common divisor (GCD), plus prime factorization steps.
Your numbers
Tips: You can enter negatives; signs are ignored for GCD/LCM. If any value is 0, LCM is 0. For clearer steps, keep values ≤ ~1e12.
Results
Show prime factorization & steps
Input | Prime factorization |
---|---|
12 | 2^2 × 3 |
18 | 2 × 3^2 |
42 | 2 × 3 × 7 |
GCD via primes: take the minimum exponent of each prime appearing in all numbers:GCD = 2 × 3 = 6
LCM via primes: take the maximum exponent of each prime across the numbers:LCM = 2^2 × 3^2 × 7 = 252
Alternatively, compute repeatedly with the Euclidean algorithm: gcd(a,b)=gcd(b,a mod b)
and lcm(a,b)=|a·b|/gcd(a,b)
, then reduce across all inputs.
Results interpretation
- GCD is the largest integer dividing all inputs—useful for simplifying fractions.
- LCM is the smallest positive integer that’s a multiple of all inputs—useful for aligning cycles or denominators.
- If any input is 0, the LCM is 0; GCD becomes the GCD of the remaining non-zero numbers.
- Negative signs don’t affect GCD/LCM; results are non-negative by convention.
How this calculator works
Formulas & assumptions
Euclidean algorithm (GCD): repeatedly replace (a,b)
with (b, a mod b)
until b=0
. The remaining a
is the GCD.
LCM from GCD: lcm(a,b)=|a·b|/gcd(a,b)
. For multiple numbers, reduce pairwise.
Prime factorization view: write each integer as ∏ piei. GCD uses the min exponents across inputs; LCM uses the max exponents.
Assumptions: integers only; sign ignored; 0 handled by the standard conventions above.
Use cases & examples
Example 1: Inputs 12, 18, 42 → GCD = 6, LCM = 252. Fractions with denominators 12, 18, 42 share a common denominator of 252.
Example 2: Machine cycles 8s, 12s, 20s → GCD = 4 (shared tick), LCM = 120s (all align).
Example 3: −24, 0, 60 → LCM = 0; GCD(−24,60)=12.
LCM vs. GCD: Why They Matter and How to Use Them
Our LCM & GCD calculator turns list-of-integers problems into fast, reliable answers. The greatest common divisor (GCD) explains how far you can factor numbers down in common—vital for simplifying fractions, reducing ratios, and finding a common “beat” in periodic tasks. The least common multiple (LCM) runs the same logic in reverse: it’s the smallest number that all inputs “fit into” cleanly, which is exactly what you want when merging denominators, aligning schedules, or synchronizing cycles.
From a practical standpoint, two complementary methods dominate. The first is the Euclidean algorithm, which is extremely fast even for large integers: keep replacing (a,b)
with (b, a mod b)
until one becomes zero. The remaining value is the GCD. Once you have GCD, you get LCM via lcm(a,b) = |a·b| / gcd(a,b)
, and for more than two numbers you just reduce pairwise. The second method is the prime factorization view, where each number becomes a product of primes to certain powers. The GCD collects the minimum exponents for primes seen across the list, while the LCM collects the maximum exponents. This method is highly visual and makes the relationship between the two quantities obvious.
In everyday workflows, these ideas show up everywhere. Simplifying a fraction like 126/210
? Compute gcd(126,210)=42
, divide numerator and denominator by 42, and you’re done. Combining denominators like 8, 12, and 20 in a single arithmetic expression? The LCM is 120, so everything scales neatly. Engineers use LCM to align component refresh intervals; planners use it to find when recurring events coincide; developers use it to reason abouttick rates and batching windows. Meanwhile, GCD sits behind cryptographic primitives, polynomial arithmetic, and number-theoretic algorithms.
A few conventions help avoid confusion. If any input is 0, the LCM is defined as 0, because zero has every integer as a divisor yet contributes no positive multiples. For GCD, zero simply drops out:gcd(0,n)=|n|
. Negative signs don’t change the results; both LCM and GCD are reported asnon-negative. When your list is long, reducing pairwise keeps computations stable and fast. And if you need a common denominator for fractions, the LCM is precisely the number you’re looking for.
With the calculator above you can mix small and large integers, add or remove rows as needed, and see both methods: the compact Euclidean reduction and the more explanatory prime-factor table. Enter your integers, copy a shareable link with inputs, and you’ll have justified results ready for classwork, planning, or code.