Skip to content

Instantly share code, notes, and snippets.

@jonatasemidio
Created May 4, 2015 19:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonatasemidio/2175a842b324a43db24e to your computer and use it in GitHub Desktop.
Save jonatasemidio/2175a842b324a43db24e to your computer and use it in GitHub Desktop.
Algoritimo de Euclides Estendido
//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