Created
October 26, 2017 19:33
-
-
Save tuket/b8b638b88fc5a7f635ec30747ac395f9 to your computer and use it in GitHub Desktop.
simple python implementation of the extended euclidean algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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