Cod sursa(job #2738323)

Utilizator FrostfireMagirescu Tudor Frostfire Data 5 aprilie 2021 18:17:03
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.64 kb
#include <iostream>
#include <fstream>
#define ll long long

using namespace std;

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

int t;
ll x, y;

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

int main()
{
	fin >> t;
	while(t--)
		{	ll a, b, c;
			fin >> a >> b >> c;
			ll g = gcdExtins(a, b);
			cout << g << ' ' << x << ' ' << y << '\n';
			if(c % g != 0)
				{	fout << 0 << ' ' << 0 << '\n';
					continue;
				}
			fout << x * (c / g) << ' ' << y * (c / g) << '\n';
		}
	return 0;
}