标签:
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
Source
1 //It is made by jump~ 2 #include <iostream> 3 #include <cstdlib> 4 #include <cstring> 5 #include <cstdio> 6 #include <cmath> 7 #include <algorithm> 8 #include <ctime> 9 #include <vector> 10 #include <queue> 11 #include <map> 12 #include <set> 13 using namespace std; 14 typedef long long LL; 15 const int inf = (1<<30); 16 LL n,m,X,Y,L; 17 LL a,b; 18 LL GCD,ans; 19 20 inline int getint() 21 { 22 int w=0,q=0; char c=getchar(); 23 while((c<‘0‘ || c>‘9‘) && c!=‘-‘) c=getchar(); if(c==‘-‘) q=1,c=getchar(); 24 while (c>=‘0‘ && c<=‘9‘) w=w*10+c-‘0‘, c=getchar(); return q ? -w : w; 25 } 26 27 inline LL extend_gcd(LL aa,LL bb,LL &x,LL &y){ 28 if(bb==0) { 29 x=1; y=0; 30 return aa; 31 } 32 LL cun=extend_gcd(bb,aa%bb,x,y),lin=x; 33 x=y; y=lin-(aa/bb)*y; 34 return cun; 35 } 36 37 inline void work(){ 38 X=getint(); Y=getint(); m=getint(); n=getint(); L=getint(); 39 if(n==m) { printf("Impossible"); return ; }//不可能相遇 40 GCD=extend_gcd(n-m,L,a,b); 41 LL you=X-Y; 42 if(you%GCD!=0) { printf("Impossible"); return ; }//无解 43 L/=GCD; you/=GCD;//我们希望L的系数最小 44 ans=you*a; ans%=L; ans+=L; ans%=L; 45 printf("%lld",ans); 46 } 47 48 int main() 49 { 50 work(); 51 return 0; 52 }
标签:
原文地址:http://www.cnblogs.com/ljh2000-jump/p/5906572.html