Cod sursa(job #2763972)

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

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

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

int main()
{
	int t, i, a, b, c, g;
	long long 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 << x * c / g << ' ' << y * c / g << '\n';
	}
	return 0;
}