Cod sursa(job #1063265)

Utilizator oopsSoare George oops Data 21 decembrie 2013 11:30:07
Problema Algoritmul lui Euclid extins Scor 70
Compilator cpp Status done
Runda Arhiva educationala Marime 0.58 kb
//#include"stdafx.h"

#include<stdio.h>
#define ll long long

ll gcd(ll a, ll b, ll &x, ll &y)
{
	if (b == 0)
	{
		x = 1;
		y = 1;
		return a;
	}
	ll x0, y0;
	ll d;
	d = gcd(b, a%b, x0, y0);
	x = y0;
	y = x0 - y0*(a / b);
	return d;
}

int main()
{
	freopen("euclid3.in", "r", stdin);
	freopen("euclid3.out", "w", stdout);
	int t;
	scanf("%d", &t);
	while (t--)
	{
		ll a, b, c;
		scanf("%lld %lld %lld", &a, &b, &c);
		ll x, y;
		ll d;
		d = gcd(a, b, x, y);
		if (c%d)
			printf("0 0\n");
		else
			printf("%lld %lld\n", x*(c/d), y*(c/d));
	}
	return 0;
}