We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1
EXPERIMENT 1
Aim: To implement Extended Euclidean algorithm
CODE:
def gcdExtended(a, b):
# Base Case if a == 0: return b, 0, 1 gcd, x1, y1 = gcdExtended(b % a, a) #Update x and y using results of recursive call x = y1 - (b//a) * x1 y = x1 return gcd, x, y
a = int(input("Enter the first number: "))
b = int(input("Enter the second number: ")) g, x, y = gcdExtended(a, b) print("GCD of",a,"and",b, "is",g)