Cod sursa(job #1346164)

Utilizator maribMarilena Bescuca marib Data 18 februarie 2015 07:18:10
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <fstream>

using namespace std;


long long c, d, a, b, t, x, y;

long long euex(long long nr1, long long nr2, long long &x, long long &y)
{
    if(nr2==0)
    {
        x=1; y=0; return nr1;
    }
    else
    {
        long long x0, y0, dc;
        dc=euex(nr2, nr1%nr2, x, y);
        y0=y; x0=x;
        x=y0;
        y=x0-(nr1/nr2)*y0;
        return dc;
    }
}

int main()
{
    ifstream in("euclid3.in");
    ofstream out("euclid3.out");
    in>>t;
    while(t--)
    {
        in>>a>>b>>c;
        d=euex(a, b, x, y);
        if(c%d)
            out<<"0 0\n";
        else
        {
            out<<(x*c/d)<<" "<<(y*c/d)<<"\n";
        }
    }
    in.close();
    out.close();
    return 0;
}