POJ 1061 青蛙的约会【扩欧】
题意:
两只青蛙在地球同一纬度不同位置
分析:
可知,问题可转化为求
代码:
#include<iostream>
using namespace std;
typedef long long ll;
ll extgcd(ll a, ll b, ll& x,ll &y)
{
ll d = a;
if(b!=0){
d = extgcd(b, a%b, y, x);
y -= (a/b)*x;
}else {
x = 1;
y = 0;
}
return d;
}
ll cal(int a, int b, int c)
{
ll x, y;
ll gcd = extgcd(a, b, x, y);
if(c % gcd != 0) return -1;
x *= c/gcd;
b /= gcd;
if(b < 0) b = -b;
ll ans = x % b;
if(ans <= 0) ans += b;
return ans;
}
int main (void)
{
long long x, y , m , n , l;
cin>>x>>y>>m>>n>>l;
ll ans = cal(m - n, l , y-x);
if(ans == -1) cout<<"Impossible"<<endl;
else cout<<ans<<endl;
return 0;
}