How this LCM and GCD calculator works
This tool takes any list of two or more positive integers and returns two key quantities. The greatest common divisor (GCD) — identical to the greatest common factor (GCF) or highest common factor (HCF) — is the largest number that divides all of your inputs exactly. The least common multiple (LCM) is the smallest number that every input divides into without a remainder.
The GCD is computed with Euclid's algorithm, which repeatedly replaces the larger number with the remainder of dividing it by the smaller one — gcd(a, b) = gcd(b, a mod b) — until the remainder is zero. The LCM is then found with the identity lcm(a, b) = a × b ÷ gcd(a, b). For longer lists, both operations are folded across the numbers two at a time, so gcd(a, b, c) = gcd(gcd(a, b), c) and likewise for the LCM. The math runs with BigInt internally so the LCM stays exact even when it grows large.
Reference note: GCD = GCF = HCF, all the same value. The calculator accepts positive whole numbers only; decimals, negatives, zero and non-numeric text trigger a friendly error.
Frequently asked questions
- What is the GCD?
- The greatest common divisor (GCD) of a set of integers is the largest positive integer that divides every number in the set without a remainder. For example, the GCD of 12 and 18 is 6, the largest number dividing both.
- What is the LCM?
- The least common multiple (LCM) is the smallest positive integer that every number in the set divides evenly. For example, the LCM of 12 and 18 is 36, the smallest number both divide into.
- Is GCF the same as GCD?
- Yes. The greatest common factor (GCF) is just another name for the greatest common divisor (GCD); some textbooks call it the highest common factor (HCF). All three refer to the same value.
- How do you find the LCM?
- For two numbers, the LCM equals their product divided by their GCD: lcm(a, b) = a × b ÷ gcd(a, b). For more than two numbers, take the LCM of the running result with each next number in turn.
- How is the GCD calculated using Euclid's algorithm?
- Euclid's algorithm repeatedly replaces the larger number with the remainder of dividing it by the smaller one — gcd(a, b) = gcd(b, a mod b) — stopping when the remainder is zero. The last non-zero value is the GCD, with no factoring required.
- Can it handle more than two numbers?
- Yes. Enter any list of two or more positive integers separated by commas or spaces. The calculator folds the GCD and LCM across the whole list, applying the pairwise rules to every number.