Cod sursa(job #2450957)

Utilizator TheGodFather2131Alexandru Miclea TheGodFather2131 Data 25 august 2019 11:03:40
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.14 kb
//ALEXANDRU MICLEA

#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <time.h>
#include <iomanip>
#include <deque>
#include <math.h>
#include <cmath>
#include <assert.h>
#include <stack>
#include <bitset>
#include <random>
#include <chrono>

using namespace std;

#include <fstream>
ifstream cin("euclid3.in"); ofstream cout("euclid3.out");

void euclid_ext(long long a, long long b, long long& d, long long& x, long long& y) {
	if (b == 0) {
		d = a;
		x = 1; y = 0;
		cout << a << " " << b << " " << d << " " << x << " " << y << '\n';
	}
	else {
		long long x0, y0;
		euclid_ext(b, a % b, d, x0, y0);
		x = y0;
		y = x0 - (a / b) * y0;
		cout << a << " " << b << " " << d << " " << x << " " << y << '\n';
	}
}

int main() {

	long long n;

	cin >> n;

	for (int i = 1; i <= n; i++) {
		long long a, b, c, x, y, d;
		cin >> a >> b >> c;
		euclid_ext(a, b, d, x, y);
		if (c % d != 0) {
			cout << 0 << " " << 0 << '\n';
			continue;
		}
		long long m = c / d;
		cout << " " << m * x << " " << m * y << '\n';
	}

	return 0;
}