hdu2669 扩展欧几里得
1 #include<stdio.h> 2 int exgcd(__int64 a,__int64 b,__int64 &x,__int64 &y) 3 { 4 __int64 t,r; 5 if (b==0){ 6 x=1; y=0; 7 return(a); 8 } 9 r=exgcd(b,a%b,x,y); 10 t=x; x=y; y=t-a/b*y; 11 return(r); 12 } 13 int main() 14 { 15 __int64 a,b,r,x,y; 16 while (~scanf("%I64d%I64d",&a,&b)) 17 { 18 r=exgcd(a,b,x,y); 19 while (x<0){x+=b; y-=a; } 20 if (r!=1) printf("sorry\n"); 21 else printf("%I64d %I64d\n",x,y); 22 } 23 }