Cod sursa(job #2570380)

Utilizator dahaandreiDaha Andrei Codrin dahaandrei Data 4 martie 2020 16:31:36
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <stdio.h>
#include <iostream>

using namespace std;

const int MAXT = 100;

int t;
int a, b, c;

void euclid(int a, int b, int &d, int &x, int &y) {
	if (b == 0) {
		d = a;
		x = 1;
		y = 0;
	}
	else {
		int x0, y0;
		euclid(b, a % b, d, x0, y0);
		x = y0;
		y = x0 - (a / b) * y0;
	}
}

int main() {
	freopen("euclid3.in", "r", stdin);
	freopen("euclid3.out", "w", stdout);

	cin >> t;

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

	return 0;
}