Cod sursa(job #2595995)

Utilizator teos01Teodora Arsene teos01 Data 8 aprilie 2020 21:55:34
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.66 kb
#include <iostream>
#include <fstream>

using namespace std;

void cmmdc(int a, int b, int *d, int *x, int *y)
{
	if(a == 0)
	{
		*d = b;
		*x = 0;
		*y = 1;
		return;
	}
	if(b == 0)
	{
		*d = a;
		*x = 1;
		*y = 0;
		return;
	}

	int x0, y0;
	cmmdc(b, a % b, d, &x0, &y0);
	*x = y0;
	*y = x0 - (a / b)* y0;
}

int main()
{
	ifstream fin("euclid3.in");
	ofstream fout("euclid3.out");

	int n, a, b, c, x, y, d;
	fin >> n;
	for(int i=1; i<=n; i++)
	{
		fin >> a >> b >> c;
		cmmdc(a,b, &d, &x, &y);
		if(c % d != 0)
		{
			fout << "0 0\n";
		}
		else
		{
			c /= d;
			fout << x*c << " " << y*c << "\n";
		}
	}
	return 0;
}