Cod sursa(job #230128)

Utilizator vlad_DVlad Dumitriu vlad_D Data 13 decembrie 2008 01:59:28
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include <fstream>
#include <cmath>
#include <algorithm>

using namespace std;
void euclid(int a, int b, int &x, int &y) {
	if (b == 0) {
		
		x = 1;
		y = 0;
		return;
	}
	euclid(b, a%b, x, y);
	int X, Y;
	X = y;
	Y = x - (a / b) * y;
	x = X; y = Y;
}
int main() {
	ifstream fin("euclid3.in");
	ofstream fout("euclid3.out");
	int n;
	fin >> n;
	while (n--) {
		int a, b, d;
		fin >> a >> b >> d;
		if (d % __gcd(a, b)) {fout << "0 0\n"; continue;}
		int M = d /__gcd(a, b);
		int x, y;
		euclid(a, b, x, y);
		x*=M; y*=M;
		fout << x << " " << y << '\n';
	}
	return 0;
}