WORK HARD IN SILENCE LET SUCCESS MAKE THE NOISE

自己选择的路,即使是跪着也要走完!

CF 7C Line

裸拓展欧几里得

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;
typedef long long LL;

LL gcd(LL a,LL b)
{
    return b ? gcd(b,a%b):a;
}
void ex_gcd(LL a,LL b,LL &x,LL &y)
{
    if(b == 0)
    {
        x = 1;
        y = 0;
        return ;
    }
    ex_gcd(b,a%b,x,y);
    LL tmp = x;
    x = y;
    y = tmp-(a/b)*y;
}
int main()
{
    // Ax + By = -C
    LL A,B,C;
    while(cin>>A>>B>>C)
    {
        C = -C;
        LL k = gcd(A,B);
        if(C%k)
            cout<<"-1"<<endl;
        else
        {
            A /= k,B /= k,C /= k;
//            cout<<A<<" "<<B<<" "<<C<<endl;
            LL x,y;
            ex_gcd(A,B,x,y);
//            cout<<x<<" "<<y<<endl;
            x *= C;
            y *= C;
            cout<<x<<" "<<y<<endl;
        }
    }
    return 0;
}


阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/H1deonbush/article/details/46834249
个人分类: CodeForces 数论
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭