C++ algorithm to calculate least common multiple for multiple numbers

后端 未结 15 1935
太阳男子
太阳男子 2020-12-14 16:29

Is there a C++ algorithm to calculate the least common multiple for multiple numbers, like lcm(3,6,12) or lcm(5,7,9,12)?

15条回答
  •  太阳男子
    2020-12-14 17:22

    boost provides functions for calculation lcm of 2 numbers (see here)

    Then using the fact that

    lcm(a,b,c) = lcm(lcm(a,b),c)
    

    You can easily calculate lcm for multiple numbers as well

提交回复
热议问题