Cod sursa(job #2214057)

Utilizator dahaandreiDaha Andrei Codrin dahaandrei Data 18 iunie 2018 12:43:56
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>

using namespace std;

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

int cmmdc(int a, int b, int &x, int &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	int ans = cmmdc(b, a % b, x, y);
	int aux = x;
	x = y;
	y = aux - (y * (a / b));
	return ans;
}

int a, b, c, x, y;
int n;

int main() {
	in >> n;

	while (n --) {
		in >> a >> b >> c;
		x = y = 0;
		int d = cmmdc(a, b, x, y);

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

	}

	return 0;
}