Cod sursa(job #2854203)

Utilizator Solo22Stefan Solomon Solo22 Data 21 februarie 2022 01:00:17
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.75 kb
#include <cassert>
#include <fstream>
using namespace std;
ifstream cin("euclid3.in");
ofstream cout("euclid3.out");
void Euclid_extins(int a, int b, int& d, int& x, int& y) {
	if (b == 0)
		d = a, x = 1, y = 0;
	else {
		int x0, y0;
		Euclid_extins(b, a % b, d, x0, y0);
		x = y0, y = x0 - (a / b) * y0;
	}
}
int t;
int main() {
	cin >> t;
	for (int i = 1, a, b, c, d, x, y; i <= t; ++i) {
		cin >> a >> b >> c, d = 0, x = 0, y = 0;
		assert(-1000000000 <= a && a <= 1000000000);
		assert(-1000000000 <= b && b <= 1000000000);
		assert(-2000000000 <= c && c <= 2000000000 && c != 0);
		Euclid_extins(a, b, d, x, y);
		if (c % d == 0)
			cout << x * c / d << " " << y * c / d << "\n";
		else
			cout << 0 << " " << 0 << "\n";
	}
	return 0;
}