[ create a new paste ] login | about

Link: http://codepad.org/VJIRyvI8    [ raw code | fork ]

Python, pasted on Jul 30:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
def factors(n):
    yield 1
    i = 2
    limit = n**0.5
    while i <= limit:
        if n % i == 0:
            yield i
            n = n / i
            limit = n**0.5
        else:
            i += 1
    if n > 1:
        yield n

def gcd(a, b):
    return max(set(factors(a)).intersection(factors(b)))


Create a new paste based on this one


Comments: