Skip to content

GCF & LCM Calculator

Enter two or more whole numbers to get their greatest common factor and least common multiple. The answer is worked out two ways side by side — Euclid's division algorithm and the prime factorization method — so you can follow whichever one your class uses. Numbers of up to 40 digits are handled exactly.

Two or more, separated by commas or spaces. Signs are ignored: both are defined on absolute values.

Results

6

Greatest common factor (GCF)

180

Least common multiple (LCM)

3

Numbers compared

GCF by Euclid's algorithm

Divide the larger number by the smaller, then divide the last divisor by the remainder, until the remainder is 0. The last divisor is the GCF.

GCF(12, 18)

18 = 1 × 12 + 6

12 = 2 × 6 + 0

The remainder reached 0, so GCF(12, 18) = 6.

GCF(6, 30)

30 = 5 × 6 + 0

The remainder reached 0, so GCF(6, 30) = 6.

With more than two numbers, fold them in one at a time: GCF(GCF(12, 18), 30) = GCF(6, 30) = 6.

LCM from the GCF

For two numbers, LCM(a, b) = a × b ÷ GCF(a, b). With more, fold them in one at a time.

LCM(12, 18) = 12 × 18 ÷ 6 = 36

LCM(36, 30) = 36 × 30 ÷ 6 = 180

The prime factorization method

Factor each number into primes. The GCF takes every prime the numbers share at its lowest power; the LCM takes every prime that appears at its highest power.

12 = 2² × 3

18 = 2 × 3²

30 = 2 × 3 × 5

Prime121830GCF (lowest power)LCM (highest power)
22²2222²
333²333²
5——5—5

GCF = 2 × 3 = 6

LCM = 2² × 3² × 5 = 180

How to Use the GCF & LCM Calculator

  1. 1. Type the numbers. Separate them with commas or spaces: 12, 18, 30. Two numbers are enough; up to twelve are accepted. Leave out thousands separators, since a comma here starts a new number.
  2. 2. Read the two answers. The GCF and the LCM appear at the top, with a note when the GCF is 1 and the numbers are coprime.
  3. 3. Follow the method you were taught. Euclid's algorithm lists every division; the prime factorization table shows each prime's power in each number and which power the GCF and LCM take.
  4. 4. Copy the result. The copy button gives a one-line summary such as GCF(12, 18, 30) = 6; LCM(12, 18, 30) = 180.

Two Ways to Find the GCF and LCM

Euclid's algorithm

Euclid's algorithm, from Book VII of his Elements (around 300 BC), rests on one fact: the GCF of two numbers also divides their remainder. So divide the larger number by the smaller, replace the larger with the remainder, and repeat. When the remainder reaches 0, the last divisor is the GCF. For 48 and 180:

180 = 3 × 48 + 36
48 = 1 × 36 + 12
36 = 3 × 12 + 0  →  GCF(48, 180) = 12

It is fast whatever the size of the numbers: the number of divisions is never more than five times the number of digits in the smaller one. That is why it is the method computers use, and why this calculator can work with 40-digit numbers instantly.

Prime factorization

Write each number as a product of primes. The GCF is the product of the primes the numbers share, each at its lowest power; the LCM is the product of every prime that appears, each at its highest power. With 48 = 2⁴ × 3 and 180 = 2² × 3² × 5, the GCF is 2² × 3 = 12 and the LCM is 2⁴ × 3² × 5 = 720. The method makes the structure visible, but it depends on factoring, which gets slow for very large numbers.

For two numbers there is also a shortcut that links the answers: LCM(a, b) = a × b ÷ GCF(a, b). For 48 and 180, that is 8640 ÷ 12 = 720. The calculator uses it to build the LCM from the GCF.

Worked Example: 12, 18 and 30

  1. GCF of the first pair. 18 = 1 × 12 + 6, then 12 = 2 × 6 + 0, so GCF(12, 18) = 6.
  2. Fold in the third number. 30 = 5 × 6 + 0, so GCF(GCF(12, 18), 30) = GCF(6, 30) = 6.
  3. LCM, one pair at a time. LCM(12, 18) = 12 × 18 ÷ 6 = 36, then LCM(36, 30) = 36 × 30 ÷ 6 = 180.
  4. Check with primes. 12 = 2² × 3, 18 = 2 × 3² and 30 = 2 × 3 × 5. The shared primes at their lowest powers give 2 × 3 = 6; all primes at their highest powers give 2² × 3² × 5 = 180.

When You Need the GCF or the LCM

ProblemUseExample
Simplifying a fractionGCF18/30: divide both by GCF 6 to get 3/5.
Adding fractionsLCM1/12 + 1/18: the least common denominator is 36.
Splitting into equal groupsGCF12 pens and 18 pencils make at most 6 identical kits.
Lining up repeating cyclesLCMBuses every 12 and 18 minutes meet again after 36 minutes.
Factoring an expressionGCF12x + 18 = 6(2x + 3).

Frequently Asked Questions

What is the difference between the GCF and the LCM?
The greatest common factor is the largest number that divides every number in the list, so it is never larger than the smallest of them. The least common multiple is the smallest number that every number in the list divides into, so it is never smaller than the largest. For 12 and 18 the GCF is 6 and the LCM is 36.
Are GCF, GCD and HCF the same thing?
Yes. Greatest common factor (GCF), greatest common divisor (GCD) and highest common factor (HCF, the usual British term) are three names for the same number. The LCM is sometimes called the lowest common multiple.
What is the GCF of two prime numbers?
It is 1, because a prime's only factors are 1 and itself. Two numbers whose GCF is 1 are called coprime or relatively prime, and their LCM is simply their product: LCM(7, 11) = 77. Numbers can be coprime without being prime, like 8 and 15.
How do you find the LCM of three or more numbers?
Work one pair at a time: find the LCM of the first two, then the LCM of that result and the third number, and so on. Or factor every number into primes and multiply each prime at the highest power it reaches in any of them.
Why can't I enter 0?
Every whole number divides 0, so GCF(0, n) is simply n, and LCM(0, n) is 0 by convention — neither needs a calculation, and 0 has no prime factorization to show. Remove the 0 and the calculator compares the remaining numbers.
Does GCF × LCM always equal the product of the numbers?
Only for two numbers: GCF(a, b) × LCM(a, b) = a × b. With three or more it fails — for 2, 4 and 8 the GCF is 2 and the LCM is 8, so their product is 16, not 64.

Related Tools

More in Math Calculators

See all Math Calculators