Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <algorithm>
- typedef long long ll
- template<typename T>
- T gcd_ext(const T a, const T b, T& x, T& y)
- {
- if (b == 0)
- {
- x = 1;
- y = 0;
- return a;
- }
- const T d = gcd_ext(b, a % b, x, y);
- x -= (a / b) * y;
- std::swap(x, y);
- return d;
- }
- int main()
- {
- ll a = 0, b = 0, x = 0, y = 0, c = 0;
- std::scanf("%lld%lld%lld", &a, &b, &c);
- const ll d = gcd_ext(a, b, &x, &y);
- if (c % d != 0)
- std::puts("-1");
- else
- {
- ll t = 0;
- const ll Y = y;
- const ll X = x;
- x = (c / d) * X;
- y = (c / d) * Y;
- if (x == 0)
- goto END;
- else if (x > 0)
- {
- while (x > 0)
- {
- t--;
- x = (c / d) * X + t * (b / d);
- y = (c / d) * Y - t * (a / d);
- }
- if (x == 0)
- goto END;
- t++; //доходим до сюда, когда x < 0
- x = (c / d) * X + t * (b / d);
- y = (c / d) * Y - t * (a / d);
- }
- else
- {
- while (x < 0)
- {
- t++;
- x = (c / d) * X + t * (b / d);
- y = (c / d) * Y - t * (a / d);
- }
- }
- END: std::printf("%lld %lld", x, y);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement