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

后端 未结 14 1858

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:42

    The most efficient way to calculate LCM - Time Complexity - O( log(min(a,b)) )

    Fundamental Formula - LCM(a,b) = (a*b) / GCD(a,b)

    The time comlexity of GCD(a,b) is O( log(min(a,b)) )

    Here you can find the code in C, C++, C#, Python etc. click here

    Thanks !

提交回复
热议问题