[codeforces]7C

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} 51018 to 5 ⋅ 1 0 18 5·10^{18} 51018 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) (2109A,B,C2109) — 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;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值