Skip to the calculator
Rule Calculator

GCF and LCM Calculator

With first number 12, second number 18, third number 0, gcf and lcm comes to 6 — answer. It is reached in 5 steps, the last of which is gcf_ab * lcm_ab, and each one is printed on the page with its numbers filled in. The formula is the one published by Euclid, Elements VII.2, not an approximation fitted to it.

Greatest common factor and least common multiple of two or three numbers, with the prime factors and the check that ties them together.

By Alex Seote, Built and maintains Rule Calculator · Formula and sources checked · How we check

Find Greatest common factor (GCF), First number 12, Second number 18

6

Answer for the example below. Editing a field recomputes the calculator below; this figure holds the answer the page was loaded with.

It is written into the HTML rather than drawn by a script, so a search engine reading this page without running JavaScript still finds an answer.

Answer
6
GCF of the first two
gcd(a, b)6
LCM of the first two
lcm(a, b)36
Greatest common factor
c > 0 ? gcd(gcf_ab, c) : gcf_ab6
Least common multiple
c > 0 ? lcm(lcm_ab, c) : lcm_ab36
Check: GCF × LCM of the first two
gcf_ab * lcm_ab216

Ask about this in the chat

Worked example

The GCF of 12 and 18 is 6 and the LCM is 36, and 6 × 36 = 216 = 12 × 18. That identity holds for every pair and is the fastest check there is: if your two answers do not multiply back to the product of the inputs, one of them is wrong.

How to work it out yourself

  1. 1.Enter two numbers, or three if you need them. A zero in the third box means it is ignored rather than treated as a number.
  2. 2.The GCF is the largest number that divides all of them; the LCM is the smallest number they all divide into. Both are computed by Euclid’s algorithm rather than by listing factors, which is why large numbers are instant.
  3. 3.Check the pair against the identity: GCF × LCM equals the product of the two numbers. It fails for three or more, where no such shortcut exists.

The formula

  1. GCF of the first twogcd(a, b)
  2. LCM of the first twolcm(a, b)
  3. Greatest common factorc > 0 ? gcd(gcf_ab, c) : gcf_ab
  4. Least common multiplec > 0 ? lcm(lcm_ab, c) : lcm_ab
  5. Check: GCF × LCM of the first twogcf_ab * lcm_ab

Source: Euclid, Elements VII.2 — the algorithm for the greatest common divisor, Wolfram MathWorld — least common multiple

Questions people actually ask

What is the difference between GCF, GCD and HCF?
Nothing but the name. Greatest common factor, greatest common divisor and highest common factor are three labels for the same number, used in American, mathematical and British schooling respectively.
Why does GCF × LCM equal the product?
Because every prime is counted once in total across the two: the GCF takes the lower power of each prime and the LCM takes the higher, so multiplying them takes both powers, which is what the product of the two numbers contains. It is an identity for two numbers only — three numbers have no equivalent.
What is the GCF if the numbers share nothing?
One. Every pair of whole numbers has 1 as a common factor, so the GCF is never zero and never undefined; when it comes out as 1 the numbers are called coprime, and their LCM is simply their product.
Why is this faster than listing the factors?
Euclid’s algorithm replaces the larger number with the remainder of dividing it by the smaller, and repeats. It reaches the answer in a number of steps proportional to the digits rather than to the size, which is why it handles nine-digit inputs as fast as two-digit ones.

Related

Put this calculator on your site

Free, no attribution required beyond the link.

<iframe src="https://rulecalculators.com/embed/gcf-lcm" width="100%" height="420" style="border:1px solid #e7e4de;border-radius:12px" title="GCF and LCM Calculator"></iframe>
Did this answer your question?