Cod sursa(job #2458797)

Utilizator Johnny07Savu Ioan-Daniel Johnny07 Data 21 septembrie 2019 15:34:00
Problema Algoritmul lui Euclid extins Scor 50
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.65 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");


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

		*x = y0;
		*y = x0 - (a / b) * y0;

	}

}




int main()
{
	int a, b, c;
	int t;
	int x=0, y=0, d;
	f >> t;
	for (int i = 1; i <= t; i++)
	{

		f >> a >> b >> c;
		euclid(a, b, &d, &x, &y);
		//cout << "test";
		if (c % d == 0) g << x * c / d << " " << y * c / d << endl;
		else g << 0 << " " << 0 << endl;


	}
	

}