123456789101112131415161718
int gcdex(int a,int b,int &x,int &y) { int d,dp,xp,yp; if(b==0) { d = a; x = 1; y = 0; } else { dp = gcdex(b,a%b,xp,yp); d = dp; x = yp; y = xp - (a/b)*yp; } return d; }