Cod sursa(job #659471)

Utilizator IoanaMarMarussi Ioana IoanaMar Data 10 ianuarie 2012 17:47:09
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>

using namespace std;

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

int main()
{
    int a, b, c, d, x, y;
    short T;
    f>>T;
    for (;T;--T)
        {
            f>>a>>b>>c;
            euc(a, b, d, x, y);

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

void euc(int a, int b, int &d, int &x, int &y)
{
    if (!b)
    {
        d=a;
        x=1;
        y=0;
    }
    else
    {
        int u,l;
        euc(b, a%b, d,u,l);
        x=1;
        y=u-(a/b)*l;

    }
}