Cod sursa(job #2763973)

Utilizator popoviciAna16Popovici Ana popoviciAna16 Data 18 iulie 2021 13:16:48
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.56 kb
#include <iostream>
#include <fstream>
using namespace std;

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

void euclid (int a, int b, int &g, int &x, int &y)
{
	if (b == 0)
	{
		g = a;
		x = 1;
		y = 0;
	}
	else
	{
		int x2, y2;
		euclid (b, a%b, g, x2, y2);
		x = y2;
		y = x2 - 1ll * a/b * y2;
	}
}

int main()
{
	int t, i, a, b, c, g;
	int x, y;
	fin >> t;
	for (i = 1; i<=t; i++)
	{
		fin >> a >> b >> c;
		euclid (a, b, g, x, y);
		if (c % g != 0)
			fout << "0 0\n";
		else
			fout << 1ll * x * c / g << ' ' << 1ll * y * c / g << '\n';
	}
	return 0;
}