time limit per test : 1 second
memory limit per test : 256 megabytes
A line on the plane is described by an equation
A
x
+
B
y
+
C
=
0
Ax + By + C = 0
Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from
−
5
⋅
1
0
18
- 5·10^{18}
− 5⋅1018 to
5
⋅
1
0
18
5·10^{18}
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
⋅
1
0
9
≤
A
,
B
,
C
≤
2
⋅
1
0
9
)
( - 2·10^9 ≤ A, B, C ≤ 2·10^9)
( − 2⋅109 ≤ A, B, C ≤ 2⋅109) — corresponding coefficients of the line equation. It is guaranteed that
A
2
+
B
2
>
0
A^2 + B^2 > 0
A2 + B2 > 0.
###Output
If the required point exists, output its coordinates, otherwise output
−
1
-1
−1.
####Examples
Input
2 5 3
Output
6 -3
题意:
模板题,求方程
A
x
+
B
y
+
C
=
0
Ax+By+C=0
Ax+By+C=0 的一个整数解。
题解:
扩展欧几里得
#include<bits/stdc++.h>
#define base 107
#define ll long long
using namespace std;
ll exgcd(ll a,ll b,ll &x,ll &y){
if(b==0){
x=1;y=0;return a;
}
ll d=exgcd(b,a%b,x,y),temp=x;
x=y;
y=temp-a/b*y;
return d;
}
ll a,b,ta,tb,c,d,x,y;
int main(){
scanf("%I64d%I64d%I64d",&a,&b,&c);
ta=abs(a);tb=abs(b);
d=exgcd(ta,tb,x,y);
if(-c%d!=0)return puts("-1"),0;
c/=d;
x*=-c;y*=-c;
if(a<0)x=-x;
if(b<0)y=-y;
printf("%I64d %I64d\n",x,y);
return 0;
}