Cod sursa(job #1184282)

Utilizator stef93Stefan Gilca stef93 Data 11 mai 2014 23:17:00
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.74 kb
#include <cstdio>
#include <cstdlib>
#pragma warning(disable: 4996)
using namespace std;

int euclid(int a, int b, int &x, int &y)
{
	if (b == 0)
	{
		x = 1;
		y = 0;
		return a;
	}
	else
	{
		int cmmdc = euclid(b, a%b, x, y) , xx;
		xx = x;
		x = y;
		y = xx - (a / b) * y;
		return cmmdc;
	}
}

int main()
{
	freopen("euclid3.in", "r", stdin);
	freopen("euclid3.out", "w", stdout);
	int nc;
	int a, b, c , cmmdc;
	int x, y , s1 , s2;

	scanf("%d", &nc);

	while (nc--)
	{
		scanf("%d %d %d", &a, &b, &c);

		cmmdc = euclid(a, b, x, y);

		if (c % cmmdc == 0)
		{
			s1 = x * (c / cmmdc);
			s2 = y * (c / cmmdc);

			printf("%d %d\n", s1, s2);
		}
		else
		{
			printf("0 0\n");
		}
	}
	
	return 0;
}