**
航电oj:青蛙的约会
**
#题目描述
#一般的方法会超时将方程变为不定式来计算而不是循环求解
#知识点
不定式计算 ax+by=c;
#代码
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
typedef long long LL;/// 不定式 ax+by=c 的通解和特解
void gcd(LL a, LL b, LL& d, LL& x, LL& y)///?
{
if (!b)
{
d=a;
x=1;
y=0;
}
else
{
gcd(b, a%b, d, y, x);
y -= x*(a/b);
}
}
LL math(LL a, LL b, LL c)
{
LL GCD, x0, y0;
gcd(a, b, GCD, x0, y0);/// x0 y0 为一次解
if (c%GCD)
return -1;
LL sum = b/GCD;
sum = llabs(sum);//变为正
x0 *= c/GCD;
y0 *= c/GCD;///通解
return (x0%sum+sum)%sum;///通解中找特解
}
int main()
{
LL x, y, m, n, L;
scanf("%lld%lld%lld%lld%lld", &x, &y, &m, &n, &L);
LL ans = math(m-n, L, y-x); /// (m-n)a + L*k = y-x -> ax + by = c;
if (ans != -1)
printf("%lld\n", ans);
else
printf("Impossible\n");
return 0;
}
#总结
数学硬伤 还不太懂 生搬硬套 插个眼先