什么是找到正数的GCD最快的方法是什么? [英] what is the fastest way to find the gcd of n numbers?

查看:212
本文介绍了什么是找到正数的GCD最快的方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是计算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.

这篇关于什么是找到正数的GCD最快的方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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