模拟
参考:https://blog.csdn.net/zs120197/article/details/52074657
ps:用扩展欧几里得写,效率更高,但不太好理解。
AC代码:
//模拟
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int x, y, m, n, L;
int X, Y,ans = 0;
bool flag = 0;
cin >> x >> y >> m >> n >> L;
X = x, Y = y;
while (1) {
x = (x + m) % L;
y = (y + n) % L;
ans++;
if (x == y)//循环出口
break;
if (x == X && y == Y) {//两者回到各自起点,不会相遇
flag = 1;
break;
}
}
if (flag)
cout << "Impossible" << endl;
else
cout << ans << endl;
return 0;
}