Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 90247 | Accepted: 16392 |
Description
Input
Output
Sample Input
1 2 3 4 5
Sample Output
4
#include<iostream> using namespace std; typedef __int64 inti ; inti gcd(inti a,inti b,inti &x1,inti &y1) { inti d; if(!b)d=a,x1=1,y1=0; else{ d=gcd(b,a%b,y1,x1); y1-=x1*(a/b); } return d; } int main(){ inti x,y,n,m,l; cin>>x>>y>>n>>m>>l; inti d=y-x; inti a=n-m; inti x1,y1; inti b=gcd(a,l,x1,y1); if(d%b)cout<<"Impossible\n"; else{ inti t=l/b; x1=(d/b*x1%t+t)%t; while(x1<0){x1+=l;} cout<<x1<<endl; } return 0; }
原文地址:http://blog.csdn.net/hyccfy/article/details/38515435