Cod sursa(job #852999)

Utilizator ericptsStavarache Petru Eric ericpts Data 11 ianuarie 2013 23:22:20
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <fstream>
using namespace std;

int euclid(int a,int b,int &x,int &y)
{
    if(!b)
    {
        x = 1;
        y = 0;
        return a;
    }
    else
    {
        int x0,y0,d;
        d = euclid(b,a%b,x0,y0);
        x = y0;
        y = x0 - (a/b) * y0;
        return d;
    }
}

int main()
{
    ifstream in("euclid3.in");
    ofstream out("euclid3.out");

    int T,a,b,d,c;
    int x,y;
    in >> T;
    while(T--)
    {
        in >> a >> b >> c;
        d = euclid(a,b,x,y);
        if(c%d)
            x = y = 0;
        out << x * c / d << " " << y * c / d << "\n";
    }
    return 0;
}