Cod sursa(job #2436162)

Utilizator RaulG99Gioanca Raul RaulG99 Data 4 iulie 2019 18:45:12
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <vector>
#include <fstream>

using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");

int a, b, d, x, y, n;

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()
{
	f >> n;
	for (int i = 0; i < n; i++)
	{
		int c, n, x0, y0;
		f >> a >> b >> c;
		euclid(a, b, &d, &x, &y);

		if (c % d != 0)
		{
			g << 0 << " " << 0 << "\n";
		}
		else
		{
			n = c / d;
			x0 = x * n;
			y0 = y * n;
			g << x0 << " " << y0 << "\n";
		}


	}

}