Cod sursa(job #146522)

Utilizator andrei_infoMirestean Andrei andrei_info Data 1 martie 2008 20:51:39
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
#include <stdio.h>
#include <stdlib.h>

int T;
long a,b,c;

long gcd( long a, long b, long &x, long &y)
{

	long x0, y0, d;

	if ( b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}

	d = gcd(b, a%b, x0, y0);
	x = y0;
	y = x0 - (a/b) * y0;
	return d;
}


int main()
{
	freopen("euclid3.in", "r", stdin);
	freopen("euclid3.out", "w", stdout);

	scanf("%d", &T);

	for (; T>0; T--)
	{
		scanf("%ld %ld %ld", &a, &b, &c);
		long d,x,y;

		d = gcd(a,b,x,y);

		if ( c % d )
			printf("0 0\n");
		else
			printf("%ld %ld\n", x*(c/d), y * (c/d));
	}
	return 0;
}