Cod sursa(job #1241388)

Utilizator adysnookAdrian Munteanu adysnook Data 13 octombrie 2014 14:43:57
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>

using namespace std;

ifstream in("euclid3.in");
ofstream out("euclid3.out");

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;
	}
}
inline void ee(int a, int b, int c){
	int d, x, y;
	euclid(a, b, &d, &x, &y);
	out << c / d*x << " " << c / d*y;
}

int main(){
	int t, i, a, b, c;
	in >> t;
	for (i = 0; i < t; ++i){
		in >> a >> b >> c;
		ee(a, b, c);
		out << "\n";
	}

	return 0;
}