Cod sursa(job #1739716)

Utilizator tavy14tIlie Octavian tavy14t Data 10 august 2016 00:05:36
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.63 kb
#include <iostream>
#include <fstream>
using namespace std;

ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

int gcd(int a, int b, int &x, int &y)
{
	if(b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}

	int tempX, tempY, GCD;
	GCD = gcd(b, a%b, tempX, tempY);
	
	x = tempY;
	y = tempX - (a / b) * tempY;
	return GCD;
}

int main()
{
	int noTests;
	fin >> noTests;
	for (int i = 0; i < noTests; i++)
	{
		int GCD, a, b, c, x, y;
		fin >> a >> b >> c;
		GCD = gcd(a, b, x, y);
		
		if (c % GCD != 0)
			fout << "0 0" << endl;
		else{
			fout << x * (c / GCD)<< " " << y * (c / GCD) << endl;
		}
	}
}