Cod sursa(job #2643152)

Utilizator MiclosMiclos Eduard Miclos Data 18 august 2020 23:10:30
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.71 kb
#include <iostream>
#include <fstream>
using namespace std;

const long N_MAX = 2000000000;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

void extendedGCD(long a, long b, long* x, long* y, long* r) {
	if (b == 0) {
		*x = 1;
		*y = 0;
		*r = a;
	}
	else {
		long x0, y0;
		extendedGCD(b, a % b, &x0, &y0, r);
		*x = y0;
		*y = x0 - (a / b) * y0;
	}
}


int main() {
	int T;
	fin >> T;

	while (T--) {
		long a, b, c, x, y, gcd;
		fin >> a >> b >> c;

		extendedGCD(a, b, &x, &y, &gcd);
		
		if (c % gcd != 0) {
			fout << 0 << " " << 0 << '\n';
			continue;
		}

		fout << (x * c) / gcd << " " << (y * c) / gcd << '\n';
	}

	fin.close(); fout.close();

	return 0;
}