CF 7C Line

来源:互联网 发布:开盘摇号软件 编辑:程序博客网 时间:2024/05/02 00:47

裸拓展欧几里得

#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;}


0 0
原创粉丝点击