Articles

# Python之美：最大公约数

fractions.gcd(a, b) Return the greatest common divisor of the integers a and b. If either a or b is nonzero, then the absolute value of gcd(a, b) is the largest integer that divides both a and b. gcd(a,b) has the same sign as b if b is nonzero; otherwise it takes the sign of a. gcd(0, 0) returns 0.

def gcd(a, b):
while b:
a, b = b, a%b
return a