最小公倍数为3个或更多的数字 [英] Least common multiple for 3 or more numbers

查看:120
本文介绍了最小公倍数为3个或更多的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算多个数字的最小公倍数?

How do you calculate the least common multiple of multiple numbers?

到目前为止,我只能够计算出它两个数字之间。但不知道如何将它扩大到计算3个或更多的数字。

So far I've only been able to calculate it between two numbers. But have no idea how to expand it to calculate 3 or more numbers.

到目前为止,这是我做到了。

So far this is how I did it

LCM = num1 * num2 /  gcd ( num1 , num2 )

使用GCD是函数计算最大公约数的数字。使用欧几里德算法

With gcd is the function to calculate the greatest common divisor for the numbers. Using euclidean algorithm

不过,我想不出如何计算它的3个或更多的数字。

But I can't figure out how to calculate it for 3 or more numbers.

推荐答案

您可以通过反复计算两个数字的LCM计算超过两个号码的LCM,即

You can compute the LCM of more than two numbers by iteratively computing the LCM of two numbers, i.e.

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

这篇关于最小公倍数为3个或更多的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆