Cod sursa(job #1435251)

Utilizator agamanAlexandru Gaman agaman Data 12 mai 2015 17:51:43
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.84 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 = y_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 q = (c/d);
		if (c%d == 0) {
			cout << (q*x) << " " << (q*y) << "\n";
		} else {
			cout << "0 0\n";
		}
		cout << x << " " << y << " " << d << " " << c << "\n";
	}

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