Cod sursa(job #1170421)

Utilizator dnprxDan Pracsiu dnprx Data 13 aprilie 2014 15:59:04
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include <fstream>

using namespace std;

inline long long Cmmdc( long long a, long long b, long long &x, long long &y )
{
    long long x0, y0, d;
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}

	d = Cmmdc( b, a % b, x0, y0 );

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

int main()
{
    long long i, nrTeste, a, b, c, d, x, y;
	ifstream fin("euclid3.in");
	ofstream fout("euclid3.out");

	fin >> nrTeste;
	for (i = 1; i <= nrTeste; ++i)
	{
	    fin >> a >> b >> c;

		d = Cmmdc(a, b, x, y);

		if (c % d != 0)
			fout << "0 0\n";
		else
		{
		    x = x * c / d;
		    y = y * c / d;
		    fout << x << " " << y << "\n";
		}
	}

	return 0;
}