C. Line
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.
Sample test(s)
input
2 5 3
output
6 -3
1 #include<cstdio> 2 #include<cstring> 3 using namespace std; 4 5 void exgcd(int a,int b,int& d,long long& x,long long& y) 6 { 7 if(!b)d=a,x=1,y=0; 8 else 9 { 10 exgcd(b,a%b,d,y,x); 11 y-=x*(a/b); 12 } 13 } 14 15 int main() 16 { 17 int a,b,c; 18 while(scanf("%d%d%d",&a,&b,&c)!=EOF) 19 { 20 int d;long long x,y; 21 exgcd(a,b,d,x,y); 22 if(c%d!=0) 23 puts("-1"); 24 else 25 { 26 x*=c/d; 27 y*=c/d; 28 printf("%lld %lld\n",-x,-y); 29 } 30 } 31 return 0; 32 }
时间: 2024-10-10 04:07:51