记录编号 571032 评测结果 AAAAAAAAAAAAAAAAAAAAA
题目名称 [POJ 1061] 青蛙的约会 最终得分 100
用户昵称 Gravatarlihaoze 是否通过 通过
代码语言 C++ 运行时间 0.000 s
提交时间 2022-05-04 19:02:41 内存使用 0.00 MiB
显示代码纯文本
  1. #include <bits/stdc++.h>
  2. #define OPEN(_x) freopen(#_x".in", "r", stdin); freopen(#_x".out", "w", stdout)
  3. #define rep(_x, _y, _z) for (int _x = (_y); _x <= (_z); ++ _x)
  4. #define rep1(_x, _y, _z) for (int _x = (_y); _x < (_z); ++ _x)
  5. #define fi first
  6. #define se second
  7.  
  8. using i64 = long long;
  9. using PII = std::pair<int, int>;
  10.  
  11. i64 exgcd(i64 a, i64 b, i64 &x, i64 &y) {
  12. if (b == 0) { x = 1, y = 0; return a; }
  13. i64 d = exgcd(b, a % b, y, x);
  14. y -= x * (a / b);
  15. return d;
  16. }
  17.  
  18. i64 x, y, m, n, L;
  19. i64 p, t;
  20.  
  21. int main() {
  22. OPEN(poj_hama);
  23. std::ios::sync_with_stdio(false);
  24. std::cin.tie(nullptr);
  25. std::cin >> x >> y >> m >> n >> L;
  26. i64 d = exgcd(L, n - m, p, t);
  27. i64 q = L / d;
  28. if ((x - y) % d != 0) std::cout << "Impossible" << '\n';
  29. else {
  30. t *= (x - y) / d;
  31. t %= q;
  32. while (t < 0) {
  33. if (q < 0) t -= q;
  34. else t += q;
  35. }
  36. std::cout << t << '\n';
  37. }
  38. return 0;
  39. }