标签:
1 #include<cstdio> 2 #include<cstring> 3 #include<cmath> 4 #include<algorithm> 5 6 typedef long long ll; 7 8 using namespace std; 9 10 ll xx,yy; 11 12 ll exgcd(ll n,ll m) 13 { 14 if(m==0) 15 { 16 xx=1,yy=0; 17 return n; 18 } 19 ll ans=exgcd(m,n%m),t=xx; 20 xx=yy,yy=t-n/m*yy; 21 return ans; 22 } 23 24 int main() 25 { 26 ll a,b,c,d,e; 27 scanf("%lld%lld%lld%lld%lld",&a,&b,&c,&d,&e); 28 ll x=d-c,y=e,k=a-b; 29 ll g=exgcd(x,y); 30 if(k%g!=0){printf("Impossible\n");return 0;} 31 x/=g,y/=g,k/=g; 32 exgcd(x,y); 33 k=((k*xx)%e+e)%e; 34 if(!k)k=e; 35 printf("%lld",k); 36 return 0; 37 }
标签:
原文地址:http://www.cnblogs.com/tuigou/p/4628399.html