Cod sursa(job #1730080)

Utilizator ionut_paulNicoara Ionut Paul ionut_paul Data 16 iulie 2016 12:36:41
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
// http://www.infoarena.ro/problema/euclid3

#include <fstream>

using namespace std;

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

int main() {
	
	ifstream f("euclid3.in");
	ofstream g("euclid3.out");
	
	int d, x, y, n, a, b, c;
	
	f>>n;
	for(int i=0;i<n;++i){
		f>>a>>b>>c;
		euclid(a, b, &d, &x, &y);
		if(c%d!=0){
			g<<"0 0\n";
		}
		else{
			g<<x*(c/d)<<" "<<y*(c/d)<<"\n";
		}
	}
	
	g.close();
	
	return 0;
}