Cod sursa(job #1199518)

Utilizator silidragosSilion Dragos silidragos Data 19 iunie 2014 16:31:35
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include<iostream>
#include<fstream>
using namespace std;

long long gcd(long long a, long long b, long long &x, long long&y){
	if (b == 0){
		x = 1;
		y = 0;
		return a;
	}
	
	long long x0, y0, d;
	d = gcd(b, a%b, x0, y0);

	x = y0;
	y = x0 - (a / b)*y0;
	return d;

}



int main(){
	ifstream f("euclid3.in", ios::in);//Change the name
	ofstream g("euclid3.out", ios::out);//Change the name

	int T;
	long long a, b, c;
	f >> T;

	for (T; T > 0; T--){
		f >> a >> b >> c;
		long long x, y,d;
		d = gcd(a, b, x, y);
		if (c%d)
			g << "0 0\n";
		else g << x*(c/d) << " " << y*(c/d) << '\n';
	}



	f.close();
	g.close();
	return 0;
}