Skip to content

Instantly share code, notes, and snippets.

@Abreto
Last active December 13, 2015 18:18
Show Gist options
  • Save Abreto/4953786 to your computer and use it in GitHub Desktop.
Save Abreto/4953786 to your computer and use it in GitHub Desktop.
欧几里得算法
# Euclid Algorithm
def gcd(m, n):
while n != 0:
t = m
m = n
n = t % n
return m
#
def extend_euclid(m, n):
x1 = 1
x2 = 0
y1 = 0
y2 = 1
while n != 0:
t = m
m = n
q = t/n
n = t % n
t1 = x1
t2 = y1
x1 = x2
y1 = y2
x2 = t1 - q*x2
y2 = t2 - q*y2
return [m, x1, y1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment