GCD & LCM Calculator

Last updated: 2026-06-25

TL;DR

The greatest common divisor (GCD) is found with the Euclidean algorithm; the least common multiple (LCM) is a × b ÷ GCD(a, b). For three or more numbers, apply each pairwise and accumulate.

Enter integers below separated by commas or spaces to get the GCD and LCM of all of them at once.

GCD & LCM of several numbers

Enter two or more integers separated by commas (,) or spaces.

Calculations use absolute values. The LCM may lose precision beyond JavaScript's safe integer range (about 9 quadrillion).

How to use

  1. Enter numbers — Enter the integers separated by commas or spaces.
  2. Calculate — Press Calculate to compute the GCD and LCM of all entered numbers.
  3. View the result — The GCD and LCM appear in a table and can be copied.

How GCD and LCM work

The greatest common divisor (GCD) is the largest positive integer that divides all of the given numbers, while the least common multiple (LCM) is the smallest positive common multiple. They are widely used for reducing and finding common denominators of fractions, gear ratios and cycle problems.

Key GCD and LCM formulas
ItemMethodExample
GCD (two numbers)Euclidean algorithm: GCD(a, b) = GCD(b, a mod b)GCD(12, 18) = 6
LCM (two numbers)a × b ÷ GCD(a, b)LCM(12, 18) = 36
GCD (several numbers)Apply GCD pairwiseGCD(12, 18, 24) = 6
LCM (several numbers)Apply LCM pairwiseLCM(12, 18, 24) = 72
RelationshipGCD(a, b) × LCM(a, b) = a × b6 × 36 = 12 × 18

The Euclidean algorithm repeatedly replaces the larger number with the remainder of dividing it by the smaller, finding the GCD far faster than prime factorization. The GCD that underpins reduction is also used automatically in the fraction calculator; to break a number into its prime factors, see the prime factorization calculator.

Frequently Asked Questions (FAQ)

How do I find the greatest common divisor (GCD)?

Use the Euclidean algorithm: repeatedly divide the larger number by the smaller and take the remainder. When the remainder reaches 0, the last divisor is the GCD. For three or more numbers, apply it pairwise.

How do I find the least common multiple (LCM)?

For two numbers a and b, LCM(a, b) = a × b ÷ GCD(a, b). For three or more numbers, apply the LCM pairwise and accumulate.

What is the relationship between GCD and LCM?

For two numbers a and b, GCD(a, b) × LCM(a, b) = a × b always holds. This identity is valid only for two numbers and generally does not extend to three or more.

Can I enter 0 or negative numbers?

This calculator works on absolute values, so negatives are treated like positives. Since 0 is a multiple of every number, it is usually excluded from the LCM, and GCD(a, 0) = a.

Last updated: 2026-06-25