Cod sursa(job #1599990)

Utilizator Pley01Nitu Madalin Pley01 Data 14 februarie 2016 16:25:37
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include<iostream>
#include<fstream>

using namespace std;

int cmmdex(int a, int b, int& lx, int& ly)
{
	int x = 0, y = 1, q;
	lx = 1; ly = 0;
	int tx, ty, ta;

	while (b)
	{
		q = a / b;
		ta = b; b = a%b; a = ta;

		tx = x; x = lx - q * x; lx = tx;
		ty = y; y = ly - q * y; ly = ly;
	}
	return a;

}

void main()
{
	// a * x + b * y = c
	ifstream fin("euclid3.in", ios::in);
	ofstream fout("euclid3.out", ios::out);

	int T, a, b, c, x, y, d;
	fin >> T;

	for  (int  i = 0; i < T; i++)
	{
		fin >> a;
		fin >> b;
		fin >> c;
		d = cmmdex(a, b, x, y);

		if (c % d)
			fout << "0 0";
		else
			fout << x*(c / d) << " " << y*(c / d);
	}

}