Cod sursa(job #1800463)

Utilizator gamanedyGaman Eduard-Marian gamanedy Data 7 noiembrie 2016 19:55:12
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.75 kb
#include <fstream>

using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

void gcdextins(long long a, long long b,long long &x, long long&y, long long &d)
{
    if(b==0)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        long long x0,y0,d0;
        gcdextins(b,a%b,x0,y0,d0);
        d=d0;
        x=y0;
        y=x0-(a/b)*y0;
    }
}

int main()
{
    int T,i,r;
    long long a,b,c,x,y,d;
    fin>>T;
    for(i=1;i<=T;i++)
    {
        fin>>a>>b>>c;
        gcdextins(a,b,x,y,d);
        if(c%d!=0)
        {
            fout<<0<<" "<<0<<'\n';
        }
        else
        {
            r=c/d;
            fout<<x*r<<" "<<y*r<<'\n';
        }
    }
    return 0;
}