Implementing Extended Euclidean algorithm
问题 I want to make a function combine which given two integers n and m, returns a triple of integers (a, b, gcd(n, m)) such that: am + bn = gcd(n, m) Should not assume that the integers will always be positive. gcd :: Int -> Int -> Int gcd n m | n == m = n | n > m = gcd (n-m) m | n < m = gcd n (m-n) combine :: Int ->Int -> (Int,Int,Int) x1=1; y1=0; x2=0; y2=1 while ( m /=0 ) ( q=div n m ; r=mod n m ; n=m ; m=r t=x2 ; x2=x1-q*x2 ; x1=t t=y2 ; y2=y1-q*y2 ; y1=t ) combine n m = (x1,y1,gcd(n,m)) You