Cod sursa(job #2217644)

Utilizator MariaDMaria D MariaD Data 1 iulie 2018 12:12:32
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>

using namespace std;

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

int euclidExtended(int a, int b, int &x0, int &y0) {
	if (!b) {
		x0 = 1;
		y0 = 0;
		return a;
	}

	int x, y;
	int cmmdc = euclidExtended(b, a % b, x, y);

	x0 = y;
	y0 = x - (a / b) * y;
	return cmmdc;
}

int main() {
	int T, a, b, c;

	fin >> T;

	while (T) {
		fin >> a >> b >> c;
		int x, y;
		int cmmdc = euclidExtended(a, b, x, y);

		if (c % cmmdc) {
			fout << 0 << " " << 0 << "\n";
		} else {
			fout << x * (c / cmmdc) << " " << y * (c / cmmdc) << "\n"; 
		}

		T--;
	}
}