Cod sursa(job #921968)

Utilizator BitOneSAlexandru BitOne Data 21 martie 2013 20:57:32
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <cstdlib>
#include <fstream>

using namespace std;

void gcd(int a, int b, int& d, int& x, int& y)
{
    if(!b)
    {
        x = 0;
        y = 1;
        d = a;
    }
    else {
             int x0, y0;

             gcd(b, a % b, d, x0, y0);
             x = y0;
             y = x0 - (a / b) * y0;
         }
}

int main()
{
    int T, a, b, c, d, x, y;
    ifstream in("euclid3.in");
    ofstream out("euclid3.out");

    for(in >> T; T; --T)
    {
        in >> a >> b >> c;
        gcd(a, b, d, x, y);
        if(c % d) out << "0 0\n";
        else      out << (x * c / d) << ' ' << (y * c / d) << '\n';
    }

    return EXIT_SUCCESS;
}