xk+1 = yk , yk+1 = xk - a/b*yk ,(其中,x0 = 1, y0 = 0)。blog
int exgcd(int a, int b, int &x, int &y) { if (b == 0) { x = 1; y = 0; return a; } int r = exgcd(b, a%b, x, y); int tmp = y; y = x-a/b*y; x = tmp; return r; }