Cod sursa(job #2751125)

Utilizator andrei_C1Andrei Chertes andrei_C1 Data 14 mai 2021 12:16:59
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int gcd(int a, int b, int &x, int &y) {
	if(b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	int x0, y0;
	int d = gcd(b, a % b, x0, y0);
	x = y0;
	y = x0 - y0 * (a / b);
	return d;
}
int main() {
	int T;
	for(fin >> T; T--; ) {
		int a, b,  c;
		fin >> a >> b >> c;
//		cout << a << " " << b << " " << c << '\n';
		int x, y;
		int d = gcd(a, b, x, y);
		if(c % d == 0) {
			fout << x * (c / d) << " " << y * (c / d) << '\n';
		} else {
			fout << "0 0\n";
		}
	}
	return 0;
}