Cod sursa(job #661238)

Utilizator stanescu_teodorStanescu Teodor stanescu_teodor Data 14 ianuarie 2012 05:11:33
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
#include <fstream>

using namespace std;

int a,b,c,x,y,d,a1,b1,c1,t,i;

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

int main ()
{
	ifstream f ("euclid3.in");
	ofstream g ("euclid3.out");
	f >>t;
	for (i=1; i<=t; i++)
	{
		f >>a>>b>>c;
		/*b1=b; a1=a; 
		while (b1) 
		{
			c1 = a1 % b1;
			a1 = b1;
			b1 = c1;
		}*/
		euclid (a,b,d,x,y);
		if (c%d==0) 
		{
			x=x * (c/d);
			y=y * (c/d);
			g <<x << ' ' << y<<endl;
		}
		else g <<0<<' ' <<0<<endl;
	}
	return 0;
}