Cod sursa(job #3312920)

Utilizator DobraVictorDobra Victor Ioan DobraVictor Data 30 septembrie 2025 19:35:51
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>
#include <stdint.h>

void Euclid(int32_t a, int32_t b, int32_t& d, int32_t& x, int32_t& y) {
	if(!b) {
		d = a;
		x = 1;
		y = 0;
	} else {
		int32_t x0, y0;
		Euclid(b, a % b, d, x0, y0);
		x = y0;
		y = x0 - (a / b) * y0;
	}
}

int main() {
	std::ifstream fin("euclid3.in");
	std::ofstream fout("euclid3.out");

	int32_t t;
	fin >> t;

	while(t--) {
		int32_t a, b, c;
		fin >> a >> b >> c;

		int32_t d, x, y;
		Euclid(a, b, d, x, y);

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

	fin.close();
	fout.close();

	return 0;
}