Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 98763 | Accepted: 18783 |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
Source
#include <iostream> #include <cstdio> #include <cstring> #include <stack> #include <queue> #include <map> #include <set> #include <vector> #include <cmath> #include <algorithm> using namespace std; const double eps = 1e-6; const double pi = acos(-1.0); const int INF = 0x3f3f3f3f; const int MOD = 1000000007; #define LL long long #define CL(a) memset(a,0,sizeof(a)) void exgcd(LL a,LL b,LL &d,LL &x,LL &y)//扩展欧几里德 { if(!b)d=a,x=1,y=0; else { exgcd(b,a%b,d,y,x); y-=x*(a/b); } } int main() { LL xx,yy,m,n,l; while(scanf("%lld%lld%lld%lld%lld",&xx,&yy,&m,&n,&l)!=EOF) { LL d,x,y; LL a,b,c,mm; a=n-m; b=l; c=xx-yy; exgcd(a,b,d,x,y); if(c%d) printf("Impossible\n");//判断不可能的情况 else { x=x*(c/d); mm=b/d; x=(x%mm+mm)%mm; printf("%lld\n",x); } } return 0; }