C. Line
A line on the plane are described by an equation Ax + by + C = 0. Whose coordinates is integer numbers from -5 10- 5 10-Inc-- Lusive, or to the find out such points does not exist.
Input
The first line contains three integers a, B and C ( -2 109≤ a, C9>b, C ≤2 109)-corresponding coefficients of the line equation. It's 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 namespacestd;4 5 voidEXGCD (intAintBint& D,Long Long& X,Long Long&y)6 {7 if(!b) d=a,x=1, y=0;8 Else9 {TenEXGCD (b,a%b,d,y,x); OneY-=x* (A/b); A } - } - the intMain () - { - inta,b,c; - while(SCANF ("%d%d%d", &a,&b,&c)! =EOF) + { - intDLong Longx, y; + EXGCD (a,b,d,x,y); A if(c%d!=0) atPuts"-1"); - Else - { -x*=c/D; -y*=c/D; -printf"%lld%lld\n",-x,-y); in } - } to return 0; +}
Codeforces 7c Line (extended Euclidean)