Skip to content

Instantly share code, notes, and snippets.

@JamesTheAwesomeDude
Last active June 6, 2023 18:55
Show Gist options
  • Save JamesTheAwesomeDude/93fc4810dce911ed93ac83641b3af5a9 to your computer and use it in GitHub Desktop.
Save JamesTheAwesomeDude/93fc4810dce911ed93ac83641b3af5a9 to your computer and use it in GitHub Desktop.
extended euclidean algorithm python
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