如何计算最小公分母
也许是因为我的英语,我找不到任何东西。我想找到几个数字的最小除法值。 在德语中,它被称为:http://de.wikipedia.org/wiki/Hauptnenner 我想知道如何在 .Net 中执行此操作,因为我不敢相信这个问题是新问题,并且除了像在纸上那样计算“2 个分隔符和 3 个分隔符”之外还没有找到解决方案。
如果能得到任何建议将很高兴。
问候
I could not find anything because of my English perhaps. I want to find the smallest dividing value of several numbers.
In German it is called: http://de.wikipedia.org/wiki/Hauptnenner
I want to know how to do this in .Net because I cannot believe that this question is new and have not found a solution except to do it like on paper to count the "2 dividers and 3 dividers".
Would be great to get any advice.
Regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
该网站已经告诉您如何做到这一点:找到所有分母集合的最小公倍数。您可以利用最小公倍数和最大公约数之间的关系(请参阅维基百科)并简单地使用欧几里德算法(也可在维基百科上找到)。
Schau nach, wie du den ggT(groessten gemeinsamen Teiler berechnest -> Euklids Algorithmus)。 Danach kannst du den Hauptnenner aus dem kgV der Nenner berechnen。
The website already tells you how to do it: Find the least common multiple for the set of all denominators. You can exploit the relation between least common multiple and greatest common divisor (see Wikipedia) and simply use the Euclidean algorithm (also available on Wikipedia).
Schau nach, wie du den ggT (groessten gemeinsamen Teiler berechnest -> Euklids Algorithmus). Danach kannst du den Hauptnenner aus dem kgV der Nenner berechnen.
最小公分母通常称为最小公乘数 LCM。两个数字 a 和 b 的 LCM(表示为 L(a, b))与这些数字的最大公约数 GCD(a, b) 之间存在关系:
GCD(a, b) 可以使用以下公式非常有效地计算 : 欧几里得算法。
此外,三个数字的 LCM 计算可以简化为两个数字的 LCM:
从而再次简化为两个数字的 GCD 计算。现在,计算 N 个数字的 LCM 的过程应该很明显了。
The Least Common Denominator is usually called the Least Common Multiplier LCM. There is a relation between LCM of two numbers a and b, denoted L(a, b), and the Greatest Common Divisor GCD(a, b) of these numbers:
The GCD(a, b) can be computed very efficiently using the Euclidean Algorithm.
Further, the computation of LCM for three numbers can be reduced to LCM of two numbers:
and hence again to computation of GCD of two numbers. Now, the procedure to compute LCM for N numbers should be obvious.
Jiri 展示了 LCM 和 GCD 如何简化为计算两个数字的 GCD。杰夫的算法对于大量数据来说太慢了。下面是一个算法的草图,该算法是输入数字长度的多项式,将它们称为 X 和 Y:
多项式复杂度的偶数-奇数组合证明事实上,在每两次迭代中,我们至少将其中一个数字减少至少一半
Jiri showed how LCM and GCD reduce to computing the GCD of two numbers. Jeff's algorithm is too slow for large numbers. Here's the sketch of an algorithm that's polynomial in the length of the input numbers, call them X and Y:
proof of the polynomial complexity comes from the fact that in every two iterations, we reduce at least one of the numbers by at least half
我一直在寻找与此类似的东西并提出了这个解决方案。我发现的大多数解决方案都是针对两个数字的,而我的解决方案需要处理未知数量的数字。不管怎样,这就是我想出来的。它对我有用,也许对你也有用。
I was looking for something similar to this and came up with this solution. Most solutions I found were for two numbers and my solution needed to handle an unknown quantity of numbers. Anyway, this is what I came up with. It works for me, and perhaps it will work for you.