Cod sursa(job #1909666)

Utilizator lflorin29Florin Laiu lflorin29 Data 7 martie 2017 13:28:38
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 2.61 kb
#include <bits/stdc++.h>

using namespace std;

int GCD;

void euclid(int a, int b, int &x, int &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		GCD = a;
		return;
	}

	int xx, yy;
	euclid(b, a % b, xx, yy);
	x = yy;
	y = xx - (a / b) * yy;
}

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

	int t;
	cin >> t;

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