Advertisement
pb_jiang

ABC340F

Feb 11th, 2024
732
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. #include <assert.h>
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. #ifndef __DEBUG__
  5. #define dbg(...) 42
  6. #endif
  7. template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
  8.  
  9. using ll = __int128;
  10. using pii = pair<int, int>;
  11. using pll = pair<ll, ll>;
  12. using vl = vector<ll>;
  13. using vi = vector<int>;
  14. using i128 = __int128;
  15.  
  16. std::ostream &operator<<(std::ostream &o, const __int128 &x)
  17. {
  18.     if (x < 0)
  19.         return o << "-" << -x;
  20.     if (x < 10)
  21.         return o << (char) (x + '0');
  22.     return o << x / 10 << (char) (x % 10 + '0');
  23. }
  24.  
  25. i128 ext_gcd(i128 x, i128 y, i128 &a, i128 &b)
  26. {
  27.     if (y == 0) {
  28.         a = 1, b = 0;
  29.         return x;
  30.     }
  31.     i128 ans = ext_gcd(y, x % y, b, a);
  32.     b -= x / y * a;
  33.     return ans;
  34. }
  35.  
  36. int main(int argc, char **argv)
  37. {
  38.     long long ox, oy;
  39.     cin >> ox >> oy;
  40.  
  41.     i128 x = ox, y = oy, tg = 2, a, b;
  42.     i128 g = ext_gcd(x, -y, a, b);
  43.     // if (g > tg) { // WA should take absolute value of g;
  44.     if (::abs(g) > tg) { // AC
  45.         cout << -1 << endl;
  46.         return 0;
  47.     }
  48.     a *= tg / g, b *= tg / g;
  49.     cout << b << ' ' << a << endl;
  50.     return 0;
  51. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement