Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <vector>
- #include <cmath>
- #include <string>
- #include <algorithm>
- #include <string>
- #include <deque>
- #include <iomanip>
- #include <cstddef>
- #define F first
- #define S second
- using namespace std;
- long long d = 5000000000000000000;
- long long gcd_ext(long long& x, long long& y, long long a, long long b)
- {
- if (b == 0)
- {
- x = 1;
- y = 0;
- return a;
- }
- long long x1, y1;
- long long g = gcd_ext(x1, y1, b, a%b);
- x = y1;
- y = x1 - y1 * (a / b);
- return g;
- }
- int main()
- {
- ios_base::sync_with_stdio(0);
- long long a, b, c;
- cin >> a >> b >> c;
- c *= -1;
- long long x, y;
- bool f = abs(a) < abs(b);
- if (f)
- swap(a, b);
- long long ans = gcd_ext(x, y, abs(a), abs(b));
- if (c % ans)
- {
- cout << -1 << endl;
- return 0;
- }
- if (a < 0)
- x *= -1;
- x /= ans;
- x *= c;
- if (b < 0)
- y *= -1;
- y /= ans;
- y *= c;
- if (f)
- swap(x, y);
- if (abs(x) <= d && abs(y) <= d)
- cout << x << " " << y;
- else
- cout << -1;
- return 0;
- }
Add Comment
Please, Sign In to add comment