Cod sursa(job #1949455)

Utilizator catalinionut123Winter is Coming catalinionut123 Data 2 aprilie 2017 01:28:21
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.79 kb
// Problema rucsacului.cpp : Defines the entry point for the console application.
#include "stdafx.h"
#include <iostream>
#include <fstream>
using namespace std;

int t, a, b, c;

int gcd(int a, int b, int &x, int &y)
{
	if (b == 0)
	{  
		x = 1;
		y = 0;
		return a;
	}
	int x0, y0, d;
	d = gcd(b, a%b, x0, y0);

	x = y0;
	y = x0 - (a / b)*y0;
    
	cout << x << " " << y << " " << x0 << " " << y0 << " " << d<<"\n";
	return d;

}



int main()
{
	ifstream fin("euclid3.in");
	ofstream fout("euclid3.out");


	fin >> t;
	for (int i = 0; i < t; i++)
	{
		fin >> a >> b >> c;

		int d, x, y;
		d = gcd(a, b, x, y);

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

	}

	system("PAUSE");
    return 0;
}