标签:
Time Limit: 1000MS | Memory Limit: 10000K | |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
Source
#include<iostream> #include<string> #include<cstring> #include<algorithm> #include<cstdio> using namespace std; #define ll long long #define esp 1e-13 const int N=1e4+10,M=1e6+50000,inf=1e9+10,mod=1000000007; void extend_Euclid(ll a, ll b, ll &x, ll &y) { if(b == 0) { x = 1; y = 0; return; } extend_Euclid(b, a % b, x, y); ll tmp = x; x = y; y = tmp - (a / b) * y; } ll gcd(ll a,ll b) { if(b==0) return a; return gcd(b,a%b); } int main() { ll x,y,i,z,t; ll n,m,l; while(~scanf("%lld%lld%lld%lld%lld",&x,&y,&m,&n,&l)) { ll c=((y-x)%l+l)%l; ll a=m-n; ll j,k; if(c%gcd(a,l)==0) { extend_Euclid(a,l,j,k); ll ans=j*(c/gcd(a,l)); ans=(ans%(l/gcd(abs(a),l))+(l/gcd(l,abs(a))))%(l/gcd(abs(a),l)); printf("%lld\n",ans); } else printf("Impossible\n"); } return 0; }
标签:
原文地址:http://www.cnblogs.com/jhz033/p/5766115.html