Cod sursa(job #2518994)

Utilizator Rares31100Popa Rares Rares31100 Data 6 ianuarie 2020 21:03:59
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <bits/stdc++.h>
#define LL long long

using namespace std;

ifstream in("euclid3.in");
ofstream out("euclid3.out");

LL t,a,b,c;

void cmmdc(LL a,LL b,LL &d,LL &x,LL &y)
{
    if(b==0)
    {
        x=1;y=0;d=a;
        return;
    }

    cmmdc(b,a%b,d,x,y);
    x=y;
    y=(d-a*x)/b;
}

int main()
{
    in>>t;

    while(t--)
    {
        LL x,y,d;
        in>>a>>b>>c;

        cmmdc(a,b,d,x,y);

        if(c%d)
            out<<"0 0\n";
        else
            out<<x*(c/d)<<' '<<y*(c/d)<<'\n';
    }

    return 0;
}