Cod sursa(job #610258)

Utilizator SteveStefan Eniceicu Steve Data 26 august 2011 07:44:03
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream.h>

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

int main ()
{
	short T, i;
	long a, b, c, x, y, d;
	ifstream fin ("euclid3.in");
	ofstream fout ("euclid3.out");
	fin >> T;
	for (i = 0; i < T; i++)
	{
		fin >> a >> b >> c;
		d = euclid (a, b, x, y);
		if (c % d) fout << "0 0\n";
		else fout << x * (c / d) << " " << y * (c / d) << "\n";
	}
	fin.close ();
	fout.close ();
	return 0;
}