2010-06-03 22 views

cevap

18

the 3.1.2 source code online göre, burada Python-3.1.2/Lib/fractions.py tanımlanan gcd var:

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 

Yani evet, saf Python ile yazılmış Öklit algoritması, bu.

+0

+1. Kesin! –

+2

IPython kullanıyorsanız, kaynak kodunu "gcd" yazarak hemen görebilirsiniz. – endolith

+0

Bu aslında: "import fraksiyonları", sonra: fraksiyonları =. – syntagma

İlgili konular