HomeMath › GCD and LCM Calculator

GCD and LCM Calculator

Computes the greatest common divisor (highest common factor) and least common multiple of two or more integers with the Euclidean algorithm.

When to use

You need the GCD/HCF or LCM of a list of integers, e.g. to reduce fractions, find a common denominator or check whether numbers are coprime.

Do not use when: You need the prime factors themselves (use prime-factorization) or want to reduce a single fraction (use fraction-simplifier).

Formula

gcd(a, b) by the Euclidean algorithm (gcd(a, b) = gcd(b, a mod b)); lcm(a, b) = |a × b| / gcd(a, b); both are folded over the list: gcd(a, b, c) = gcd(gcd(a, b), c)

Inputs

ParameterTypeUnitRequiredDescription
numbersnumber_listyesTwo or more integers, comma-separated (e.g. 12, 18, 24). Negative values are treated by their absolute value.

Outputs

OutputTypeUnitDescription
gcdintegerGreatest common divisor of all the numbers.
lcmintegerLeast common multiple of all the numbers.
coprimebooleantrue when the GCD is 1 (the numbers share no common factor).

Example

12 and 18: {"numbers":[12,18]}{"gcd":6,"lcm":36,"coprime":false}

4, 6 and 8: {"numbers":[4,6,8]}{"gcd":2,"lcm":24,"coprime":false}

GET https://tttkmbb.com/api/v1/calculate/gcd-lcm?numbers=12%2C18

Machine access

Sources

FAQ

Is HCF the same as GCD?

Yes. Highest common factor (HCF), greatest common factor (GCF) and greatest common divisor (GCD) are the same quantity.

How large can the numbers be?

Any integers whose LCM stays below 2^53 (about 9 × 10^15); larger results cannot be represented exactly and return an error.

Related calculators