GCD and LCM Calculator

Enter up to 100 signed integers, each with at most 30 digits. Signs are ignored in GCD and LCM. If any value is zero, the LCM is zero.

Results

Enter your values and select Calculate.

lcm⁡(a,b)=∣ab∣gcd⁡(a,b)\operatorname{lcm}(a,b)=\frac{|ab|}{\gcd(a,b)}

About this tool

This calculator finds the greatest common divisor (GCD) and least common multiple (LCM) of a list of integers. The GCD is the largest positive integer that divides every number in the list, and the LCM is the smallest positive integer that every number divides into. Students use them to simplify fractions and find common denominators, and they also appear in scheduling and gear-ratio problems. The tool uses exact integer arithmetic, so large values stay precise.

How it works

Type or paste the integers you want to compare, separated by spaces, commas, semicolons or line breaks. You can enter just two numbers or a list of up to 100, and minus signs are allowed but ignored. The tool returns the greatest common divisor and the least common multiple of the whole list.

The GCD comes from the Euclidean algorithm, which repeatedly replaces the larger number with the remainder of a division until the remainder is zero. The LCM is built up pair by pair with the formula below, dividing by the GCD so the intermediate numbers stay as small as possible. Both steps use exact integer arithmetic, so even 30-digit inputs give exact results.

lcm⁡(a,b)=∣ab∣gcd⁡(a,b)\operatorname{lcm}(a,b)=\frac{|ab|}{\gcd(a,b)}

Example

The default list is 12, 18 and 24. Their prime factorizations are 12=22⋅312 = 2^2 \cdot 3, 18=2⋅3218 = 2 \cdot 3^2 and 24=23⋅324 = 2^3 \cdot 3. The GCD takes the lowest power of each shared prime: 21⋅31=62^1 \cdot 3^1 = 6. The LCM takes the highest power of each prime that appears: 23⋅32=722^3 \cdot 3^2 = 72. The tool reports a greatest common divisor of 6 and a least common multiple of 72.

The Euclidean algorithm reaches the same answer without factoring. For 12 and 18, 18 divided by 12 leaves 6, and 12 divided by 6 leaves 0, so their GCD is 6; 24 is also divisible by 6, so the GCD of the list stays 6. For the LCM, lcm⁡(12,18)=12×18/6=36\operatorname{lcm}(12,18) = 12 \times 18 / 6 = 36, then lcm⁡(36,24)=36×24/12=72\operatorname{lcm}(36,24) = 36 \times 24 / 12 = 72.

Assumptions and limits

Enter up to 100 integers, each with at most 30 digits, separated by spaces, commas or semicolons. Decimals and fractions are not accepted. Signs are ignored, so results are never negative. If any value is zero, the LCM is reported as zero. The tool returns the two results only, not the factorizations.

Frequently asked questions

What is the difference between GCD and LCM?

The GCD is the largest number that divides all the inputs, while the LCM is the smallest number that all the inputs divide. For 4 and 6, the GCD is 2 and the LCM is 12. In fraction work, the GCD simplifies a fraction and the LCM gives the lowest common denominator.

Is GCD the same as GCF or HCF?

Yes. Greatest common factor (GCF) and highest common factor (HCF) are other names for the greatest common divisor. Textbooks in different countries prefer different names, but the calculation and the result are identical.

How are GCD and LCM related?

For two positive integers, the product of the GCD and LCM equals the product of the numbers: gcd⁡(a,b)⋅lcm⁡(a,b)=ab\gcd(a,b) \cdot \operatorname{lcm}(a,b) = ab. This relationship does not hold in general for three or more numbers. For 4 and 6, the GCD 2 times the LCM 12 is 24, which equals 4 × 6. For 2, 4 and 8 the GCD is 2 and the LCM is 8, but their product is 64.

What does it mean if the GCD is 1?

The numbers are coprime, meaning they share no common factor other than 1. For two coprime numbers, the LCM is simply their product. For example, 8 and 15 have a GCD of 1, so their LCM is 120. Numbers can be coprime without being prime themselves.

How is the LCM used for real-life schedules?

The LCM tells you when repeating cycles line up again. If one bus leaves every 12 minutes and another every 18 minutes, and both leave together now, they next leave together after lcm⁡(12,18)=36\operatorname{lcm}(12,18) = 36 minutes. The same idea applies to gear teeth, rotating shifts and blinking lights.

Link with your values

Add these parameters to this page’s address to open it with the values filled in, for example to share a calculation or to link to it from an AI assistant. The result is calculated in the browser: the page HTML shows an example for the default values, and the tool sets the data-url-params attribute once the link’s values are applied.

ParameterValueIf omitted
valuesValues separated by spaces or commasvalues separated by commas: 2,4,4,6required

Examples

  • ?values=84,126,210
  • ?values=1071,462

Write decimals with a point. Encode a space as %20, + as %2B, # as %23 and & as %26.

Result elements: [data-result-block="gcd_lcm_calculator"]