Advertisement
nac13k

GCD Extendido

Jul 3rd, 2013
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. from sys import argv
  2.  
  3. def egcd(a,b):
  4.     c = a % b
  5.     if c == 0:
  6.         return (b,0,1)
  7.     (r,x,y) = egcd(b,c)
  8.     return (r,y, x - (y * (a/b)))
  9.  
  10. def gcd(a,b):
  11.     if a%b == 0:
  12.         return b
  13.     return gcd(b, a%b)
  14.  
  15. def iGCD(a, b):
  16.     print recursivo(a,b)
  17.     c =  a%b
  18.     while True:
  19.         print a,b,c
  20.         (a, b) = (b, c)
  21.         c = a%b
  22.         if  c == 0:
  23.             return True
  24.  
  25. if __name__=='__main__':
  26.     print egcd(1,2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement