Cod sursa(job #2409995)

Utilizator LucaSeriSeritan Luca LucaSeri Data 19 aprilie 2019 17:06:12
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1025;

int dp[MAXN][MAXN];

int gcd(int a, int b, int &x, int &y) {
	if(!b){
		x = 1;
		y = 0;
		return a;
	}

	int x0, y0, d;
	d = gcd(b, a%b, x0, y0);
	
	x = y0;
	y = x0 - (a/b)*y0;
	
	return d;
}
int main() {
	#ifdef BLAT
		freopen("input", "r", stdin);
	#else
		freopen("euclid3.in", "r", stdin);
		freopen("euclid3.out", "w", stdout);
	#endif

	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int t;
	cin >> t;

	while(t--) {
		int a, b, c;
		cin >> a >> b >> c;

		int d, x, y;
		d = gcd(a, b, x, y);

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