Cod sursa(job #1350057)

Utilizator mateidanutDanut Gabriel Matei mateidanut Data 20 februarie 2015 17:22:47
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <fstream>
using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

long long t, a, b, c, d, x, y;

void Euclid (long long a, long long b, long long &d, long long &x, long long &y)
{	if (b==0)
	{	d=a;
		x=1;
		y=0;
	}
	else
	{	Euclid(b, a%b, d, x, y);
		long long X, Y;
		X=x;
		Y=y;
		x=Y;
		y=X-(a/b)*Y;
	}
}


int main()
{	f>>t;
	for (; t; --t)
	{	f>>a>>b>>c;
		d=x=y=0;
		Euclid(a, b, d, x, y);
		if (c%d!=0) g<<"0 0\n";
		else
		{	x=x*c/d;
			y=y*c/d;
			g<<x<<' '<<y<<'\n';
		}
	}
    return 0;
}