标签:
1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstdlib> 5 #include<cmath> 6 #include<cstring> 7 using namespace std; 8 const int INF=0x3f3f3f3f; 9 typedef long long LL; 10 void e_gcd(LL a,LL b,LL &d,LL &x,LL &y){ 11 if(!b){ 12 d=a; 13 x=1;y=0; 14 } 15 else{ 16 e_gcd(b,a%b,d,x,y); 17 LL temp=x; 18 x=y; 19 y=temp-a/b*y; 20 } 21 } 22 void cal(LL a,LL b){ 23 LL d,x,y; 24 e_gcd(a,b,d,x,y); 25 //printf("%lld %lld %lld %lld\n",a,b,x,y); 26 if(d!=1){ 27 puts("Inf"); 28 return; 29 } 30 /* if(b<0)b=-b; 31 LL ans=x%b; 32 //printf("%lld\n",x); 33 if(ans<0)ans+=b; 34 if(a<0)a=-a; 35 y%=a; 36 if(y<0)y+=a; 37 // printf("%lld %lld %lld\n",ans,t,y); 38 printf("%lld\n",max(a*ans-1,b*y-1);*/ 39 printf("%lld\n",a*b-a-b); 40 } 41 int main(){ 42 LL a,b; 43 while(~scanf("%lld%lld",&a,&b),a|b){ 44 cal(a,b); 45 } 46 return 0; 47 }
标签:
原文地址:http://www.cnblogs.com/handsomecui/p/4914425.html