Python3
def gcdExtended(a, b):
if a = = 0 :
return b, 0 , 1
gcd,x1,y1 = gcdExtended(b % a, a)
x = y1 - (b / / a) * x1
y = x1
return gcd,x,y
a, b = 35 , 15
g, x, y = gcdExtended(a, b)
print ( "gcd(" , a , "," , b, ") = " , g)
|
Output:
gcd(35, 15) = 5
Time Complexity: O(log(max(A, B)))
Auxiliary Space: O(log(max(A, B))), keeping recursion stack in mind.
Please refer complete article on Basic and Extended Euclidean algorithms for more details!
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
21 Jun, 2022
Like Article
Save Article