Cod sursa(job #2255713)

Utilizator flibiaVisanu Cristian flibia Data 7 octombrie 2018 14:33:44
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 kb
#include <bits/stdc++.h>
#define ll long long

using namespace std;

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

int t;
ll a, b, c, d, x, y;

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

int main(){
	in >> t;
	while(t--){
		in >> a >> b >> c;
		x = y = d = 0;
		gcd(a, b, d, x, y);
		if(c % d)
			out << "0 0\n";
		else out << x * (c / d) << ' ' << y * (c / d) << '\n';
	}
	return 0;
}