Cod sursa(job #1039990)

Utilizator L.DanielLungu Daniel L.Daniel Data 23 noiembrie 2013 20:29:50
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <fstream>
using namespace std;
void euclid(int a, int b, int &d, int &x, int &y)
{
	if (b == 0) {
		d = a;
		x = 1;
		y = 0;
	}
	else {
		int x0, y0;
		euclid(b, a % b, d, x0, y0);
		x = y0;
		y = x0 - (a / b) * y0;
	}
}

int main()
{fstream f("euclid3.in", ios::in);
	fstream g("euclid3.out", ios::out);
	int n, i, a, b, c, d, x, y;
	f >> n;
	for (i = 1; i <= n; i++)
	{
		f >> a >> b >> c;
		euclid(a, b, d, x, y);
		if (c%d == 0)g << x*(c / d) << " " << y*(c/d)<< endl;
		else g << 0 << " " << 0 << endl;
	}
	return 0;
}