Created
May 4, 2015 19:29
-
-
Save jonatasemidio/2175a842b324a43db24e to your computer and use it in GitHub Desktop.
Algoritimo de Euclides Estendido
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 mdc(a, b) { return (b == 0) ? a : mdc (b, a%b) } | |
//mdc 252, 105 | |
def mdcx(a, b){ | |
def r=a; r1=b; u=1; v=0; u1=0; v1=1; | |
def rs, us, vs, q; | |
while ( r1 != 0 ) { | |
q = r/r1 as int | |
rs=r | |
us=u | |
vs=v | |
r=r1 | |
u=u1 | |
v=v1 | |
r1=rs-q*r1 | |
u1=us-q*u | |
v1=vs-q*v1 | |
} | |
[r, u, v] | |
} | |
mdcx 252, 105 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment