A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist.
Input
The first line contains three integers A, B and C ( - 2·109 ≤ A, B, C ≤ 2·109) — corresponding coefficients of the line equation. It is guaranteed that A2 + B2 > 0.
Output
If the required point exists, output its coordinates, otherwise output -1.
Examples
input
Copy
2 5 3
output
Copy
6 -3
ax+by+c=0,化为ax+by=-c/gcd(a,b)*gcd(a,b),
套拓展欧几里得就可以解出了
1 #include <bits/stdc++.h>
2usingnamespace std;
3constint maxn = 1e5 + 10;
4constint mod = 1e9 + 7;
5 typedef longlong LL;
6 LL exgcd(LL a, LL b, LL &x, LL &y) {
7if (b == 0) {
8 x = 1, y = 0;
9return a;
10 }
11 LL g = exgcd(b, a % b, x, y);
12 LL t;
13 t = x, x = y, y = t - (a / b) * y;
14return g;
15}
16int main() {
17 LL a, b, c, x, y;
18 cin >> a >> b >> c;
19 LL t = exgcd(a, b, x, y);
20if (c % t == 0) printf("%lld %lld\n", -x * c / t, -y * c / t);
21else printf("-1\n");
22return0;
23 }