C. Line
time limit per test
1 secondmemory limit per test
256 megabytesinput
standard inputoutput
standard outputA 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> 2 using namespace std; 3 const int maxn = 1e5 + 10; 4 const int mod = 1e9 + 7; 5 typedef long long LL; 6 LL exgcd(LL a, LL b, LL &x, LL &y) { 7 if (b == 0) { 8 x = 1, y = 0; 9 return a; 10 } 11 LL g = exgcd(b, a % b, x, y); 12 LL t; 13 t = x, x = y, y = t - (a / b) * y; 14 return g; 15 } 16 int main() { 17 LL a, b, c, x, y; 18 cin >> a >> b >> c; 19 LL t = exgcd(a, b, x, y); 20 if (c % t == 0) printf("%lld %lld ", -x * c / t, -y * c / t); 21 else printf("-1 "); 22 return 0; 23 }