Cod sursa(job #2455298)

Utilizator DrugeaDianaDrugea Diana DrugeaDiana Data 11 septembrie 2019 10:11:50
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.73 kb
#include <fstream>

using namespace std;
typedef long long int ULL;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");

void cmmdc(ULL a, ULL b, ULL &d, ULL &x, ULL &y)
{
    if(b==0)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        long long int x0,y0;
        cmmdc(b, a%b, d, x0, y0);
        x=y0;
        y=x0-(a/b)*y0;
    }
}
int main()
{
    ULL a,b,c,n,x,y,d;
    fin>>n;
    for(int i=1; i<=n; i++)
    {
        fin>>a>>b>>c;
        cmmdc(a,b,d,x,y);
        if(c%d!=0)
            fout<<"0 0"<<'\n';
        else{
            x=x*c/d;
            y=y*c/d;
            fout<<x<<" "<<y<<'\n';
        }
    }
    fin.close();
    fout.close();
    return 0;
}