Cod sursa(job #713906)

Utilizator netedu_andreiFII Andrei Netedu netedu_andrei Data 15 martie 2012 09:35:23
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include<stdio.h>

long x , y , xe , ye , i , t , a , b , c , d;
long rez(long a, long b, long x, long y)
{
	long d ;
	if(b == 0) 
	{
		xe = 1;
		ye = 0;
		return a;
	}
	d = rez(b, a % b, xe, ye);
	x = ye; y = xe - (a / b) * ye;
	xe = x; ye = y;
	return d;
}
int main()
{
	freopen("euclid3.in","r",stdin);
	freopen("euclid3.out","w",stdout);
	scanf("%ld",&t);
	for(i=1;i<=t;i++)
	{
		scanf("%ld %ld %ld",&a,&b,&c);
		d = rez(a , b , x , y);
		if (c % d != 0) printf("0 0\n");
		else printf("%ld %ld\n",xe * (c / d),ye * (c / d));
	}
	return 0;
}