Cod sursa(job #2862465)

Utilizator QwertyDvorakQwerty Dvorak QwertyDvorak Data 5 martie 2022 13:32:55
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.68 kb
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair

using ll = long long;

const string myf = "euclid3";
ifstream fin(myf + ".in");
ofstream fout(myf + ".out");

int extended(int a, int b, int &x, int &y) {

	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	int x0, y0;
	int d = extended(b, a % b, x0, y0);
	x = y0;
	y = x0 - (a / b) * y0;
	return d;
}


int main() {

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


	fin.close();
	fout.close();
	return 0;
}