LCM and GCF Calculator
The calculator finds the GCF (also called the HCF or GCD) with Euclid's algorithm: divide, keep the remainder, and repeat until the remainder is 0. The LCM of two numbers is their product divided by the GCF. With three or four numbers it works in pairs. For 12 and 18, the GCF is 6 and the LCM is 36.
Last updated by Ultra Calculator
LCM and GCF
How to calculate it
gcd(a, b) = gcd(b, a mod b), repeated until the remainder is 0 lcm(a, b) = a × b ÷ gcd(a, b) gcd(a, b, c) = gcd(gcd(a, b), c) lcm(a, b, c) = lcm(lcm(a, b), c)
- a, b, c
- the whole numbers you enter (a fourth number is handled the same way)
- gcd
- the greatest common factor, also called the HCF or GCD
- lcm
- the lowest (least) common multiple
- a mod b
- the remainder when a is divided by b
When the remainder reaches 0, the last number you divided by is the GCF. For exactly two numbers, gcd × lcm = a × b, which the check line shows.
Worked example
12 and 18
The GCF is 6 and the LCM is 36. The common factors are 1, 2, 3 and 6, and 6 × 36 = 216, the same as 12 × 18.
| First number | 12 |
|---|---|
| Second number | 18 |
| Greatest common factor (GCF, HCF) | 6 |
|---|---|
| Lowest common multiple (LCM) | 36 |
| How the numbers relate | Numbers share common factors |
| All common factors | 1, 2, 3, 6 |
| Euclid's algorithm, step by step | 18 = 1 × 12 + 6 12 = 2 × 6 + 0 The remainder is 0, so the GCF is 6. |
| Check: GCF × LCM | GCF × LCM = 6 × 36 = 216, the same as 12 × 18 |
How to use this calculator
- Enter the First number and Second number, both whole numbers of 1 or more.
- Add a Third number and a Fourth number if you need them, or leave those boxes blank.
- Read the Greatest common factor (GCF, HCF) and the Lowest common multiple (LCM).
- All common factors lists every number that divides all of your numbers, and How the numbers relate says whether they are coprime.
- Euclid's algorithm, step by step shows each division and its remainder. For two numbers, the Check line confirms that GCF × LCM equals their product.
Frequently asked questions
Are HCF, GCF and GCD the same thing?
Yes. Highest common factor (HCF) is the usual name in UK schools, greatest common factor (GCF) in the US, and greatest common divisor (GCD) in university maths and programming. All three mean the largest whole number that divides every number in the set.
How do you find the LCM of two numbers?
List multiples of the larger number until one is also divisible by the smaller: for 4 and 6, the multiples of 6 are 6, 12, and 12 is divisible by 4, so the LCM is 12. A faster way is to divide the product by the GCF: 4 × 6 ÷ 2 = 12.
How do you find the HCF using prime factors?
Write each number as a product of primes and multiply the primes they share, each at its lowest power. 12 = 2^2 × 3 and 18 = 2 × 3^2 share 2 and 3, so the HCF is 2 × 3 = 6.
What does it mean if the GCF is 1?
The numbers have no common factor except 1, which is called coprime or relatively prime. With three or more numbers, a GCF of 1 only means no single factor divides all of them: 6, 10 and 15 have a GCF of 1, yet each pair shares a factor.
Is GCF × LCM always equal to the numbers multiplied together?
Only for two numbers. For 2, 4 and 8 the GCF is 2 and the LCM is 8, so GCF × LCM is 16, but 2 × 4 × 8 is 64. That is why the check line appears only when you enter two numbers.
Learn more
Factors and multiples
A factor divides a number exactly, so the factors of 12 are 1, 2, 3, 4, 6 and 12. A multiple is the number times a whole number: 12, 24, 36 and so on. The GCF is the biggest factor the numbers share, and the LCM is the smallest multiple they share.
Euclid's algorithm
Any number that divides both a and b also divides the remainder of a ÷ b, so the pair can be swapped for a smaller pair with the same GCF. Repeating this shrinks the numbers quickly until the remainder is 0. Euclid set out the method in Book VII of his Elements, around 300 BC.
Coprime numbers
Numbers with a GCF of 1 are coprime. Two numbers don't have to be prime to be coprime: 8 and 15 are both composite but share no factor other than 1, so their LCM is just 8 × 15 = 120. A set of numbers is pairwise coprime only if every pair has a GCF of 1.
- Finding the lowest common denominator to add fractions such as 1/4 + 1/6 (the LCM of 4 and 6 is 12)
- Simplifying a fraction by dividing top and bottom by their HCF
- Working out when two repeating events line up: buses every 12 and 18 minutes leave together again every 36 minutes
- Cutting lengths of 24 m and 36 m into the longest equal pieces with no waste: the HCF, 12 m
- Splitting 24 pencils and 36 rubbers into the greatest number of identical packs: 12 packs, each with 2 pencils and 3 rubbers
Mixing up HCF and LCM
The HCF is never bigger than the smallest number, and the LCM is never smaller than the largest. If your HCF of 12 and 18 is 36, you have found the LCM.
Multiplying the numbers to get the LCM
The product is only the LCM when the numbers are coprime. For 12 and 18 the product is 216, but the LCM is 36.
Using product ÷ GCF for three numbers
a × b ÷ gcd(a, b) works for two numbers only. For three, find the LCM of the first two, then the LCM of that and the third, which is what the calculator does.
Reading a GCF of 1 as no shared factors at all
For three or more numbers, pairs can still share factors. 6, 10 and 15 have a GCF of 1, but 6 and 10 share 2. How the numbers relate tells you whether every pair is coprime as well, and names a pair that isn't.
Methodology and sources
Enter two to four whole numbers of 1 or more; blank optional boxes are skipped, and a decimal is refused rather than rounded. The GCF comes from Euclid's algorithm, worked through the numbers in pairs, and every division is listed in the steps. The LCM uses lcm(a, b) = a × b ÷ gcd(a, b), also in pairs. All common factors are the divisors of the GCF; when there are more than 100, the first 100 are listed. For three or four numbers with a GCF of 1, the calculator also checks every pair, so it can tell coprime from pairwise coprime. Each number can be up to 9,007,199,254,740,991, and the arithmetic uses exact whole numbers, so an LCM above that limit is still exact.