Last active
June 6, 2023 18:55
-
-
Save JamesTheAwesomeDude/93fc4810dce911ed93ac83641b3af5a9 to your computer and use it in GitHub Desktop.
extended euclidean algorithm python
This file contains 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 xgcd(a, b): | |
"https://anh.cs.luc.edu/331/notes/xgcd.pdf" | |
x, x_ = 1, 0 | |
y, y_ = 0, 1 | |
while b: | |
q, b, a = *divmod(a, b), b | |
x, x_ = x_, x - q*x_ | |
y, y_ = y_, y - q*y_ | |
#assert a0*x + b0*y == math.gcd(a0, b0) | |
return x, y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment