Cod sursa(job #1435250)

Utilizator agamanAlexandru Gaman agaman Data 12 mai 2015 17:37:18
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
#include <iostream>
#include <fstream>

#define INPUT_FILE "euclid3.in"
#define OUTPUT_FILE "euclid3.out"

std::fstream in(INPUT_FILE, std::fstream::in);
std::fstream out(OUTPUT_FILE, std::fstream::out);

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 x_aux, y_aux;
		euclid(b, a%b, d, &x_aux, &y_aux);
		*x = x_aux;
		*y = x_aux - (a/b) * y_aux;
	}
}

int main(int argc, char const *argv[])
{
	int numberOf;
	int a, b, c;
	int d, x, y;
	d = x = y = 0;
	in >> numberOf;
	for (int i = 0; i < numberOf; i++) {
		in >> a >> b >> c;
		euclid(a, b, &d, &x, &y);
		int cat = c/d;
		if (c%d == 0) {
			out << x*cat << " " << y*cat << "\n";
		} else {
			out << "0 0" << "\n";
		}
	}

	out.close();
	in.close();
	return 0;
}