Cod sursa(job #1350060)

Utilizator mateidanutDanut Gabriel Matei mateidanut Data 20 februarie 2015 17:24:22
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.55 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
	{	long long x0, y0;
		Euclid(b, a%b, d, x0, y0);
		x=y0;
		y=x0-(a/b)*y0;
	}
}


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;
}