Cod sursa(job #2908107)

Utilizator maiaauUngureanu Maia maiaau Data 1 iunie 2022 15:24:11
Problema Algoritmul lui Euclid extins Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.6 kb
#include <fstream>
#include <algorithm>
using namespace std;

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

int cmmdc_ext(int, int, int&, int&);
int t, a, b, c, d, x, y;

int main() {

	cin >> t;

	for (; t; t--) {
		cin >> a >> b >> c;
		d = cmmdc_ext(a, b, x, y);
		if (c % d) cout << "0 0\n";
		else {
			cout << 1ll * x * c / d << ' ' << 1ll* y * c / d << '\n';
		}
	}
	
	return 0;
}

int cmmdc_ext(int a, int b, int& x, int& y) {
	if (!b) {
		x = y = 1;
		return a;
	}
	int d, x1, y1;
	d = cmmdc_ext(b, a % b, x1, y1);
	x = y1;
	y = x1 - (a / b) * y1;
	return d;
}