Advertisement
Guest User

Problem P [F7]

a guest
Apr 10th, 2020
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <tuple>
  3.  
  4. using namespace std;
  5.  
  6. tuple<int, int, int> gcd(int a, int b)
  7. {
  8.     if (b == 0)
  9.         return make_tuple(a, 1, 0);
  10.  
  11.     int x1, y1, d;
  12.     tie(d, x1, y1) = gcd(b, a % b);
  13.     int x = y1;
  14.     int y = x1 - (a / b) * y1;
  15.     return make_tuple(d, x, y);
  16. }
  17.  
  18. int main()
  19. {
  20.     ios_base::sync_with_stdio(false);
  21.     cin.tie(NULL);
  22.  
  23.     int a, b, c;
  24.     cin >> a >> b >> c;
  25.  
  26.     int x1, y1, d;
  27.     tie(d, x1, y1) = gcd(a, b);
  28.     if (c % d != 0)
  29.     {
  30.         cout << "Impossible";
  31.         return 0;
  32.     }
  33.  
  34.     cout << d << " " << x1 * (c / d) << " " << y1 * (c / d);
  35.     return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement