Cod sursa(job #2202527)

Utilizator cezar.dimoiuDimoiu Cezar Gabriel cezar.dimoiu Data 9 mai 2018 00:05:04
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.6 kb
#include <bits/stdc++.h>

using namespace std;

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

int main()
{ 
	int t; 
	freopen("euclid3.in", "rt", stdin);
	freopen("euclid3.out", "rt", stdout);

	scanf("%d", &t);

	for (int i = 0; i < t; ++i)
	{
		int a, b, d, x, y, c;
		scanf("%d%d%d", &a, &b, &c);
		extended_euclid(a, b, &d, &x, &y);
		if (c % d) x = y = 0;
		else { 
			x *= c / d; 
			y *= c / d;
		}
		printf("%d %d\n", x, y);
	}

	return 0;
}