Cod sursa(job #252417)

Utilizator ada_sAda-Mihaela Solcan ada_s Data 4 februarie 2009 13:46:03
Problema Algoritmul lui Euclid extins Scor 20
Compilator cpp Status done
Runda Arhiva educationala Marime 0.59 kb
#include <stdio.h>

void euclid(long a, long b, long &d, long &x, long &y);

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

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