Cod sursa(job #2493183)

Utilizator RobysenLazarov Robert Robysen Data 16 noiembrie 2019 09:28:29
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");

void euclid(long long a, long long b, long long &d, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		d = a;
	}
	else {
		long long w, z;
		euclid(b, a%b, d, w, z);
		x = z;
		y = w - (a / b) * z;
	}
}

int main()
{
	int T, i;
	fin >> T;
	long long a, b, c, d;
	long long x = 0, y = 0;
	for (i = 0; i < T; i++) {
		fin >> a >> b >> c;
		euclid(a, b, d, x, y);
		if (c % d == 0) fout << x * c / d << ' ' << y * c / d << '\n';
		else fout << 0 << ' ' << 0 << '\n';
	}
}