标签:style class blog c code tar
拓展欧几里得的应用。
1 //Accepted 228 KB 0 ms 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 __int64 a,b,x,y; 6 __int64 extend_euclid(__int64 a,__int64 b,__int64 &x,__int64 &y) 7 { 8 if (b==0) 9 { 10 x=1; 11 y=0; 12 return a; 13 } 14 __int64 d=extend_euclid(b,a%b,x,y); 15 __int64 t=x; 16 x=y; 17 y=t-a/b*y; 18 return d; 19 } 20 __int64 gcd(__int64 a,__int64 b) 21 { 22 if (b==0) return a; 23 return gcd(b,a%b); 24 } 25 void slove() 26 { 27 if (gcd(a,b)!=1) 28 { 29 printf("sorry\n"); 30 return ; 31 } 32 extend_euclid(a,b,x,y); 33 x=(x%b+b)%b; 34 y=(1-a*x)/b; 35 printf("%I64d %I64d\n",x,y); 36 return ; 37 } 38 int main() 39 { 40 while (scanf("%I64d%I64d",&a,&b)!=EOF) 41 { 42 slove(); 43 } 44 return 0; 45 }
hdu2669Romantic,布布扣,bubuko.com
标签:style class blog c code tar
原文地址:http://www.cnblogs.com/djingjing/p/3750889.html