【POJ-1061 青蛙的约会】
题目
代码
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
LL ex_gcd(LL a, LL b, LL &x, LL &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
LL gcd = ex_gcd(b, a % b, x, y);
LL tmp = x;
x = y;
y = tmp - a / b * y;
return gcd;
}
int main()
{
LL x, y, m, n, l;
cin >> x >> y >> m >> n >> l;
LL a = n - m, b = l, c = x - y;
LL X, Y;
LL gcd = ex_gcd(a, b, X, Y);
if (c % gcd)
{
cout << "Impossible";
return 0;
}
X = X * c / gcd;
b /= gcd;
if (b < 0)
b = -b;
X = (X % b + b) % b;
cout << X;
return 0;
}
原文地址:https://blog.csdn.net/m0_73669127/article/details/142535226
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!