欧几里得最大公约数超过两个号码 [英] Euclidean greatest common divisor for more than two numbers

查看:111
本文介绍了欧几里得最大公约数超过两个号码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以举个例子寻找最大公约数算法超过两个号码?

Can someone give an example for finding greatest common divisor algorithm for more than two numbers?

我相信编程语言并不重要。

I believe programming language doesn't matter.

推荐答案

先说第一对,并得到他们的GCD,然后采取这一结果的GCD和下一个号码。最明显的优化是可以停止,如果正在运行的GCD没有到达1.我在看这一个,看看是否有任何其他的优化​​。 :)

Start with the first pair and get their GCD, then take the GCD of that result and the next number. The obvious optimization is you can stop if the running GCD ever reaches 1. I'm watching this one to see if there are any other optimizations. :)

喔,这样就可以很容易地并行,因为操作是可交换/缔

Oh, and this can be easily parallelized since the operations are commutative/associative.

这篇关于欧几里得最大公约数超过两个号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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