Cod sursa(job #2787122)

Utilizator Radu_marioRadu Mario Radu_mario Data 22 octombrie 2021 16:49:57
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.52 kb
#include <bits/stdc++.h>
using namespace std;

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

void GCD(int a, int b, int& d, int& x, int& y)
{
	if (!b)
	{
		d = a;
		return;
	}
	
	GCD(b, a % b, d, x, y);
	int cx = x;

	x = y;
	y = cx - (a / b) * x;
}

int main()
{
	int T; fin >> T;
	for (int i = 1, a, b, c, d, x = 1, y = 0; i <= T; ++i)
	{
		fin >> a >> b >> c;
		GCD(a, b, d, x, y);

		if (c % d) fout << "0 0\n";
		else fout << x * (c / d) << ' ' << y * (c / d) << '\n';
	}
	return 0;
}