Cod sursa(job #3142004)

Utilizator EricDimiC. Eric-Dimitrie EricDimi Data 18 iulie 2023 12:12:03
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.63 kb
#include <iostream>
#include <fstream>
#define ll long long
using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

ll n, a, b, c, x, y, d;

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

int main()
{
	f >> n;
	for (int i = 1; i <= n; i++)
	{
		f >> a >> b >> c;
		Euclid_Extins(a, b, d, x, y);
		if (c % d != 0)
			g << "0 0 \n";
		else
			g << (x * c) / d  << " " << (y * c) / d << "\n";
	}

	f.close();
	g.close();
	return 0;
}