Wednesday, January 31, 2018

How do you find the least common multiple between two numbers?

Hello!
Suppose that the two numbers are both >=2 (if one of the numbers is 1, the problem is trivial). Then both have its unique decomposition into prime factors. If we find this decomposition, which is not simple for large numbers, then LCM must contain the maximum degrees of all prime factors from both numbers.
Consider an example. Let a = 126, b = 108. Then a = 2^1*3^2*7, b = 2^2*3^3. The maximum degrees are 2 for 2, 3 for 3 and 1 for 7. Hence LCM(a,b) = 2^2*3^3*7 =756.
Another method is to find the greatest common divisor (for example, using Euclidean algorithm) and use the fact that a*b = LCM(a,b)*GCD(a,b).

No comments:

Post a Comment

Why is the fact that the Americans are helping the Russians important?

In the late author Tom Clancy’s first novel, The Hunt for Red October, the assistance rendered to the Russians by the United States is impor...