2010-06-03 68 views

回答

18

the 3.1.2 source code online,這裏的gcdPython-3.1.2/Lib/fractions.py定義:

def gcd(a, b): 
    """Calculate the Greatest Common Divisor of a and b. 

    Unless b==0, the result will have the same sign as b (so that when 
    b is divided by it, the result comes out positive). 
    """ 
    while b: 
     a, b = b, a%b 
    return a 

所以,是的,它是歐幾里德算法,寫在純Python。

+0

+1。權威! – 2010-06-03 02:37:04

+2

如果您使用的是IPython,您可以通過輸入'gcd ??' – endolith 2012-06-14 03:08:12

+0

立即看到源代碼。它實際上是:'import fractions',然後是:IPython中的fractions.gcd ??'。 – syntagma 2013-02-24 22:48:23

相關問題