Skip to content

Instantly share code, notes, and snippets.

@tuket
Created October 26, 2017 19:33
Show Gist options
  • Save tuket/b8b638b88fc5a7f635ec30747ac395f9 to your computer and use it in GitHub Desktop.
Save tuket/b8b638b88fc5a7f635ec30747ac395f9 to your computer and use it in GitHub Desktop.
simple python implementation of the extended euclidean algorithm
def euclides(a, b):
S = []
while a % b != 0:
S.append(a // b)
a, b = b, a % b
x1, x2 = 1, -S.pop()
while len(S):
q = S.pop()
x1, x2 = x2, x1 - x2*q
return (b, x1, x2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment