Cod sursa(job #2213685)

Utilizator dahaandreiDaha Andrei Codrin dahaandrei Data 16 iunie 2018 22:04:00
Problema Algoritmul lui Euclid extins Scor 0
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 a, b, c, x, y, n;

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

int main()
{
	in >> n;

	for (int i = 1; i <= n; ++ i) {
		in >> a >> b >> c;
		int d = cmmdc(a, b, x, y);
		if (c % d == 0) {
			out << (c / d) * x << ' ' << (c / d) * y << '\n';
		}
		else
			out << "0 0" << '\n';
	}

  return 0;
}