Cod sursa(job #1190826)

Utilizator BitOneSAlexandru BitOne Data 25 mai 2014 18:52:38
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.52 kb
#include <fstream>
#include <cstdlib>

using namespace std;

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

	gcd(b, a % b, x0, y0, d);

	x = y0;
	y = x0 - (a/ b) * y0;
    }
}

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

    for(in >> T; T; --T)
    {
	in >> a >> b >> c;
	gcd(a, b, x, y, d);

	if(c % d) out << "0 0\n";
	else x *= c / d, y *= c / d, out << x << ' ' << y << '\n';
    }
}