Python Program for Basic Euclidean algorithms
Python3
def gcd(a, b):
if a = = 0 :
return b
return gcd(b % a, a)
a = 10
b = 15
print ( "gcd(" , a , "," , b, ") = " , gcd(a, b))
a = 35
b = 10
print ( "gcd(" , a , "," , b, ") = " , gcd(a, b))
a = 31
b = 2
print ( "gcd(" , a , "," , b, ") = " , gcd(a, b))
|
Output:
GCD(10, 15) = 5
GCD(35, 10) = 5
GCD(31, 2) = 1
Time Complexity: O(Log min(a, b))
Auxiliary Space: O(Log min(a, b)), due to recursion stack.
Please refer complete article on Basic and Extended Euclidean algorithms for more details!
Last Updated :
22 Jun, 2022
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...