CodeForces

来源:互联网 发布:mac版的ps怎么破解 编辑:程序博客网 时间:2024/06/06 01:44



C. Line
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 AB 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
2 5 3
output
6 -3

思路:主要运用扩展欧几里得公式。


#include<stdio.h>__int64 extgcd(__int64 a,__int64 b,__int64 &x,__int64 &y ){    __int64  d=a;    if(b!=0)    {        d=extgcd(b,a%b,y,x);        y-=(a/b)*x;    }    else    {        x=1;        y=0;    }    return d;}int main(){    __int64 a,b,c,x,y;    while(~scanf("%I64d %I64d %I64d",&a,&b,&c))    {        __int64 k=extgcd(a,b,x,y);        if(c%k!=0)        {            printf("-1\n");        }        else printf("%I64d %I64d\n",x*(-c/k),y*(-c/k));    }    return 0;}


原创粉丝点击