GCFLCM.C: Greatest Common Factor and Least Common Multiple Calculator

Last modified on
Output
GCFLCM.C

How to Use

  • This can accept two or three inputs. The last one is optional.
  • Please input your integer from the left, in this order:
    i-1 ➡️ i-2 ➡️ i-3 (optional).
  • Type the integer on each input. Minimum value of 1.
    The maximum value:
    1. For 2 inputs: i-1 and i-2 can accept (up to) 10,000.
    2. For 3 inputs: each input accepts maximum value of 500.
    Then hit either gcf or lcm to calculate.
  • Hit reset to reset all.

Limitations

The two-input and three-input limitations are because the technique I employ in this, using the "actual" tree factoring logic flow.

For more efficient method, there's a post on Monkey Raptor. The link is below this, within "continuous division technique" post.


Purpose

This tool can be used to teach children about finding the GCF and LCM.
Or, as a reminder for us about the method.

Example
We want to find the GCF and LCM from 4 and 14.
First, get the prime factorisation from both.
We can use the tree factoring method, which yields:
  • 4 = 2 × 2 (or 22)
  • 14 = 2 × 7

GCF (Greatest Common Factor)

GCF is about the least exponent of the same factors.
Or, the largest shared common factors which can be used to divide each of the numbers without resulting remainders.

Thus, as you can see, they have the common factors of 2.
The 2 and 22.

Take the one with the least exponent.
That's the GCF ➡️ 2.

If we divide 4 or 14 by 2, each division won't produce remainders.
But if we use either 22 or 7 as the divisor, at least one of the divisions will result remainders.

LCM (Least Common Multiple)

LCM is about the highest exponent of the same factors multiplied by the different factor(s).
Or, the least positive integer which can be divided by all input numbers.

Have a look again — they share the common factors of 2 and one difference, 7.
For the same factors, take the one with the largest exponent — that is 22.
For the difference, simply put that into the multiplication.
Hence, the LCM is 22 × 7 = 4 × 7 = 28.

In other words:
  • The multiples of 4 = 4, 8, 12, 16, 20, 24, 28, 32, ...
  • The multiples of 14 = 14, 28, 42, ...
Therefore, 28 is the least common multiple of 4 and 14.

No Common Prime Factor?

Then the GCF will be 1.

And the LCM will (still) be the method above.

For example, 3 and 5.
  • The GCF is 1.
  • The LCM is 15 (3 × 5).
    The multiplication of the different factors.

Continuous Division

To learn about continuous division technique to find the GCF and LCM, here is a post on Monkey Raptor.

⬆️ I provide a JS snippet of it and an interface (demonstration) to try the method.