Cod sursa(job #1331385)

Utilizator chinmayiCobuz Cezara chinmayi Data 31 ianuarie 2015 16:26:49
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.68 kb
#include<iostream>
#include<fstream>
using namespace std;

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

int main()
{
	ifstream inFile("euclid3.in");
	ofstream outFile("euclid3.out");

	int T;
	inFile >> T;

	for (T; T; T--)
	{
		int a, b, c;
		inFile >> a >> b >> c;
		
		int x, y, d;
		d = gcd(a, b, &x, &y);

		if (c%d)
		{
			outFile << 0 << " " << 0;
			if (T > 1)
				outFile << endl;
		}
		else
		{
			outFile << x*(c / d) << " " << y*(c / d);
			if (T > 1)
				outFile << endl;
		}
	}
}