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

后端 未结 14 1897

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 14:02

    Product of 2 numbers is equal to LCM * GCD or HCF. So best way to find LCM is to find GCD and divide the product with GCD. That is, LCM(a,b) = (a*b)/GCD(a,b).

提交回复
热议问题