Files
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

35 lines
859 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
// 扩展欧几里得算法
int exgcd(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1, y = 0;
return a;
}
int d = exgcd(b, a % b, y, x);
y -= a / b * x;
return d;
}
signed main() {
int a, b, m, n, l;
// 青蛙 A 的出发点坐标是 a,青蛙 B 的出发点坐标是 b
// 青蛙 A 一次能跳 m 米,青蛙 B 一次能跳 n 米
// 纬度线总长 L 米
cin >> a >> b >> m >> n >> l;
int x, y;
int d = exgcd(m - n, -l, x, y);
if ((b - a) % d)
puts("Impossible"); // 永远也碰不到
else {
x = (b - a) / d * x; // 按照比例扩大
int t = abs(l / d);
cout << (x % t + t) % t << endl; // 返回正的余数
}
}