What is the most efficient way to calculate the least common multiple of two integers?

后端 未结 14 1878

What is the most efficient way to calculate the least common multiple of two integers?

I just came up with this, but it definitely leaves something to be desired.

14条回答
  •  庸人自扰
    2020-12-07 13:59

    I think that the approach of "reduction by the greatest common divider" should be faster. Start by calculating the GCD (e.g. using Euclid's algorithm), then divide the product of the two numbers by the GCD.

提交回复
热议问题