2017-10-01 12:50:45 +00:00
|
|
|
# https://en.wikipedia.org/wiki/Euclidean_algorithm
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2017-10-01 12:50:45 +00:00
|
|
|
def euclidean_gcd(a, b):
|
|
|
|
while b:
|
|
|
|
t = b
|
|
|
|
b = a % b
|
|
|
|
a = t
|
|
|
|
return a
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
2017-10-01 12:50:45 +00:00
|
|
|
def main():
|
|
|
|
print("GCD(3, 5) = " + str(euclidean_gcd(3, 5)))
|
|
|
|
print("GCD(5, 3) = " + str(euclidean_gcd(5, 3)))
|
|
|
|
print("GCD(1, 3) = " + str(euclidean_gcd(1, 3)))
|
|
|
|
print("GCD(3, 6) = " + str(euclidean_gcd(3, 6)))
|
|
|
|
print("GCD(6, 3) = " + str(euclidean_gcd(6, 3)))
|
|
|
|
|
2019-10-05 05:14:13 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2017-10-01 12:50:45 +00:00
|
|
|
main()
|