double_trouble

Untitled

Nov 5th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <vector>
  4. #include <cmath>
  5. #include <string>
  6. #include <algorithm>
  7. #include <string>
  8. #include <deque>
  9. #include <iomanip>
  10. #include <cstddef>
  11.  
  12. #define F first
  13. #define S second
  14.  
  15. using namespace std;
  16. long long d = 5000000000000000000;
  17.  
  18. long long gcd_ext(long long& x, long long& y, long long a, long long b)
  19. {
  20.     if (b == 0)
  21.     {
  22.         x = 1;
  23.         y = 0;
  24.         return a;
  25.     }
  26.     long long x1, y1;
  27.     long long g = gcd_ext(x1, y1, b, a%b);
  28.     x = y1;
  29.     y = x1 - y1 * (a / b);
  30.     return g;
  31. }
  32.  
  33. int main()
  34. {
  35.     ios_base::sync_with_stdio(0);
  36.  
  37.     long long a, b, c;
  38.     cin >> a >> b >> c;
  39.     c *= -1;
  40.  
  41.     long long x, y;
  42.     bool f = abs(a) < abs(b);
  43.     if (f)
  44.         swap(a, b);
  45.     long long ans = gcd_ext(x, y, abs(a), abs(b));
  46.  
  47.     if (c % ans)
  48.     {
  49.         cout << -1 << endl;
  50.         return 0;
  51.     }
  52.     if (a < 0)
  53.         x *= -1;
  54.     x /= ans;
  55.     x *= c;
  56.     if (b < 0)
  57.         y *= -1;
  58.     y /= ans;
  59.     y *= c;
  60.     if (f)
  61.         swap(x, y);
  62.     if (abs(x) <= d && abs(y) <= d)
  63.         cout << x << " " << y;
  64.     else
  65.         cout << -1;
  66.  
  67.     return 0;
  68. }
Add Comment
Please, Sign In to add comment