GCD




Pay Notebook Creator: Salah Ahmed0
Set Container: Numerical CPU with TINY Memory for 10 Minutes 0
Total0

greatest common denominator

Find the gcd using the euclidean algo

In [3]:
# Crosscompute
a_int = 1701
b_int = 3768
In [4]:
a, b = a_int, b_int
In [5]:
def gcd(a, b):
    if a < b:
        return gcd(b, a)
    elif b == 0:
        return a
    else:
        r = a % b
        return gcd(b, r)
In [6]:
f = gcd(a, b)
In [7]:
print('gcd(%d,%d) = %d' % (a, b, f))
gcd(1701, 3768) = 3