标签:nbsp bsp a* main anti style names div mil
#include <bits/stdc++.h> using namespace std; long long e_gcd(long long a,long long b,long long &x,long long &y) { if(b==0) { x=1;y=0; return a; } long long ans=e_gcd(b,a%b,x,y); long long temp=x; x=y; y=temp-a/b*y; return ans; } long long cal(long long a,long long b,long long c) { long long x,y; long long gcd=e_gcd(a,b,x,y); if(c%gcd) return -1; long long k=c/gcd; x*=k,y*=k;//相当于x=x0+b/gcd*c if(b<0) b=-b; long long ans=x%b;//最小的x if(ans<=0) ans+=b; return ans; } int main() { long long a,b; while(cin>>a>>b) { long long ans=cal(a,b,1); if(ans==-1) printf("sorry\n"); else printf("%lld %lld\n",ans,(1-ans*a)/b); } return 0; }
标签:nbsp bsp a* main anti style names div mil
原文地址:https://www.cnblogs.com/Fy1999/p/8783489.html