7C Line

扩展欧几里德算法模板,虽然看了,博客还有小紫书,但是还是理解的很模糊,果然数学底子很差。。。后面在写感悟吧,再来补充。上传一张小紫书的欧几里德算法模板讲解这里写图片描述。这里还有别的博主详细的讲解传送门:http://blog.csdn.net/yanghui07216/article/details/49388143

                                    C. Line
                                time limit per test1 second
                                memory limit per test256 megabytes
                                inputstandard input
                                outputstandard 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 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.

Examples
input
2 5 3
output
6 -3

        #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    typedef long long ll;
    void gcd(ll a,ll b,ll &d,ll &x,ll &y)
    {
        if(!b)
        {
            x=1;
            y=0;
            d=a;
        }
        else
        {
            gcd(b,a%b,d,y,x);
            y-=x*(a/b);
        }
    }
    int main()
    {
        ll a,b,c,x,y,d;
        while(cin>>a>>b>>c)
        {
            gcd(a,b,d,x,y);
            if(c%d!=0)
                puts("-1");
            else
                cout<<-x*(c/d)<<' '<<-y*(c/d)<<endl;
        }

        return 0;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

落凡尘.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值