Skip to content

Commit 76eefae

Browse files
authored
Merge pull request #62 from Phantsure/patch-3
Create euclidean_algo_GCD_extended.py
2 parents 3424058 + 5ba71b7 commit 76eefae

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Python program to demonstrate working of extended
2+
# Euclidean Algorithm
3+
4+
# function for extended Euclidean Algorithm
5+
def gcdExtended(a, b, x, y):
6+
# Base Case
7+
if a == 0 :
8+
x = 0
9+
y = 1
10+
return b
11+
12+
x1 = 1
13+
y1 = 1 # To store results of recursive call
14+
gcd = gcdExtended(b%a, a, x1, y1)
15+
16+
# Update x and y using results of recursive
17+
# call
18+
x = y1 - (b/a) * x1
19+
y = x1
20+
21+
return gcd
22+
23+
# example input
24+
x = 1
25+
y = 1
26+
a = 35
27+
b = 15
28+
print(gcdExtended(a, b, x, y))

0 commit comments

Comments
 (0)