Cod sursa(job #1755438)

Utilizator marcudaniel12Marcu Tudor Daniel marcudaniel12 Data 10 septembrie 2016 10:56:16
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.61 kb
#include <fstream>
using namespace std;
ifstream fi("euclid3.in");
ofstream fo("euclid3.out");
int T,t,a,b,c,x,y,d;
int gcd(int a, int b, int &x, int &y)
{
    int x0,y0,d;
    if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
    d=gcd(b,a%b,x0,y0);
    x=y0;
    y=x0-(a/b)*y0;
    return d;
}

int main()
{
    fi>>T;
    for(t=1; t<=T; t++)
    {
        fi>>a>>b>>c;
        x=0;
        y=0;
        d=gcd(a,b,x,y);
        if (c%d)
            fo<<"0 0\n";
        else
            fo<<x*(c/d)<<" "<<y*(c/d)<<"\n";
    }
    fi.close();
    fo.close();
    return 0;
}