Cod sursa(job #1218751)

Utilizator ptquake10ptquake10 ptquake10 Data 12 august 2014 14:22:14
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <iostream>
using namespace std;

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

int main() {
	long long t, a, b, c, d, x, y;
	freopen("euclid3.in", "r", stdin);
	//freopen("input.txt","r",stdin);
	freopen("euclid3.out", "w", stdout);
	
	cin >> t;
	while(t--) {
		cin >> a >> b >> c;
		gcd(x, y, a, b, d);
		if (c % d == 0) {
			cout << x * (c/d) << " " << y * (c/d) << "\n";
		} else {
			cout << "0 0\n";
		}
	}
	
	
	return 0;
}