Cod sursa(job #1755102)

Utilizator MarkMargineanu Cristian Mark Data 9 septembrie 2016 14:17:24
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.86 kb
//============================================================================
// Name        : euclid3.cpp
// Author      : Margineanu Cristian
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

int x, y, d;

void extendedEuclid(int a, int b){
	if (b == 0){
		x = 1;
		y = 0;
		d = a;
		return;
	}
	extendedEuclid(b, a%b);
	int x1 = y;
	int y1 = x - (a / b) * y;
	x = x1;
	y = y1;
}

int main() {
	int t, a, b, c;
	fin >> t;
	for (int i = 1; i <= t; i++){
		fin >> a >> b >> c;
		extendedEuclid(a, b);
		if (c%d == 0){
			d = c / d;
			fout << x * d << ' ' << y * d << '\n';
		}
		else
			fout << "0 0\n";
	}
	fin.close();
	fout.close();
	return 0;
}