This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
#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; // 返回正的余数