1 year ago
#164163
Lukas Apple Fan
Python - Print steps of an extended euclidean algorithm
Here is the current extended euclidean algorithm I found online :
def euclideEtendu(bNombre, aModulo):
""" Algorithme d'Euclide étendu, permettant de connaître:
PGCD
Coefficients de Bézout (u, v)
Inverse modulaire de B modulo A ---> B * B^-1 mod A = 1
"""
modulo = aModulo
x = 0
y = 1
u = 1
v = 0
while bNombre != 0:
q = aModulo // bNombre
r = aModulo % bNombre
m = x - u * q
n = y - v * q
aModulo = bNombre
bNombre = r
x = u
y = v
u = m
v = n
' retourne (pgcd, u, v, inverse modulaire '
return (aModulo, x, y, x % modulo)
Here is an example :
>>> euclideEtendu(17, 13)
(1, -3, 4, 10)
And here is what I want it to return :
>>> euclideEtendu(17, 13)
1 = 13 - 3 * 4
1 = 13 - 3 * (17 - 1 * 13)
1 = 4 * 13 - 3 * 17
17x + 13y = 1
17 * -3 + 13 * 4 = 1
So adding all the "steps".
Thanks in advance.
python
euclidean-algorithm
0 Answers
Your Answer