Greatest common divisor in Python
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/usr/bin/python
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
print gcd(110,10)
print gcd(1407,3441)
print gcd(12,42)
print gcd(3121,73165603)
print gcd(3072,8388608)
|
1 2 3 4 5 6 7 8 9 10 11 12 13 | #!/usr/bin/python
def gcd(a,b):
if b==0:
return a
return gcd(b,a%b)
print gcd(110,10)
print gcd(1407,3441)
print gcd(12,42)
print gcd(3121,73165603)
print gcd(3072,8388608)
|
In mathematics, the greatest common divisor (gcd), sometimes known as the greatest common factor (gcf) or highest common factor (hcf), of two non-zero integers, is the largest positive integer that divides both numbers without remainder.
