Cod sursa(job #2720432)

Utilizator FrostfireMagirescu Tudor Frostfire Data 10 martie 2021 20:32:50
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.59 kb
#include <iostream>
#include <fstream>

using namespace std;

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

int t, x, y;

int gcd_extins(int a, int b)
{	if(!b)
		{	x = 1;
			y = 0;
			return a;
		}
	int gcd = gcd_extins(b, a % b);
	int x1 = y, y1 = x - y * (a / b);
	x = x1;
	y = y1;
	return gcd;
}

int main()
{
	fin >> t;
	while(t--)
		{	int a, b, c;
			fin >> a >> b >> c;
			x = y = 0;
			int d = gcd_extins(a, b);
			if(c % d != 0)
				fout << 0 << ' ' << 0 << '\n';
			else
				fout << x * (c / d) << ' ' << y * (c / d) << '\n';
		}
	return 0;
}