由网友(再痛丶也要坚持)分享简介:什么是计算n个数的最大公约数的最快方法是什么?what is the fastest way to compute the greatest common divisor of n numbers?推荐答案下面是我一直在寻找的答案。找到N个数字的GCD的最好办法确实是使用recursion.ie GCD(A,B...
什么是计算n个数的最大公约数的最快方法是什么?
what is the fastest way to compute the greatest common divisor of n numbers?
推荐答案
下面是我一直在寻找的答案。 找到N个数字的GCD的最好办法确实是使用recursion.ie GCD(A,B,C)= GCD(GCD(A,B),C)。但我得到超时在某些程序时,我这样做。
Here was the answer I was looking for. The best way to find the gcd of n numbers is indeed using recursion.ie gcd(a,b,c)=gcd(gcd(a,b),c). But I was getting timeouts in certain programs when I did this.
在这里需要的优化是递归应该使用的快速矩阵乘法算法求解。
The optimization that was needed here was that the recursion should be solved using fast matrix multiplication algorithm.
相关推荐
最新文章