Cod sursa(job #3246565)

Utilizator sanzianagrecuSanziana Grecu sanzianagrecu Data 3 octombrie 2024 17:37:59
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.69 kb
#include <fstream>

using namespace std;


ifstream cin("euclid3.in");
ofstream cout("euclid3.out");

int d, x, y;

void euclid_extins(int a, int b) {
	if (b == 0) {
		d = a, x = 1, y = 0;
		return ;
	}	
	else {
		int x2 = 1, x1 = 0, y2 = 0, y1 = 1;
		while (b > 0) {
			int q = a / b;
			int r = a % b;
			x = x2 - (q * x1);
			y = y2 - (q * y1);
			a = b;
			b = r;
			x2 = x1;
			x1 = x;
			y2 = y1;
			y1 = y;
		}
		d = a, x = x2, y = y2;
	}

}


int main() {

	int t;
	cin >> t;
	for (int i = 1; i <= t; ++ i) {
		int a, b, c;
		cin >> a >> b >> c;
		euclid_extins(a, b);
		if ((c % d) != 0)
			cout << 0 << ' ' << 0 << '\n';
		else
			cout << x * (c / d) << ' ' << y * (c / d) << '\n';
	}


	return 0; 
}