GCFLCM.C: Greatest Common Factor and Least Common Multiple Calculator
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:- For 2 inputs:
i-1andi-2can accept (up to) 10,000. - For 3 inputs: each input accepts maximum value of 500.
gcforlcmto calculate. - For 2 inputs:
- Hit
resetto 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
Or, as a reminder for us about the method.
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)
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)
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, ...
No Common Prime Factor?
Then the GCF will be 1.
And the LCM will (still) be the method above.
- 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.
