Cod sursa(job #1896106)

Utilizator loghin.alexandruLoghin Alexandru loghin.alexandru Data 28 februarie 2017 14:06:59
Problema Algoritmul lui Euclid extins Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.8 kb
#include <fstream>
#include <iostream>
using namespace std;

ifstream fin;
ofstream fout;

void euclidExtins(long long a,long b,long long& d,long long& x,long long& y)
{
	if(b == 0)
	{
		d=a;
		x=1;
		y=0;
	}	
	else 
	{
		long long x0,y0;
		euclidExtins(b,a%b,d,x0,y0);
		x=y0;
		y=x0-(a/b)*y0;
		//cout<<x<<' '<<y;
		//cout<<'\n';
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	long long x=0,y=0,d=0;
	int n;
	fin.open("euclid3.in");
	fout.open("euclid3.out");
	fin>>n;
	for(int i = 0; i < n; ++i)
	{
		x=y=d=0;
		long long a,b,c;
		fin>>a>>b>>c;

	    euclidExtins(a,b,d,x,y);
	    if(c%d == 0)
	    {
	    	fout<<x<<' '<<y;
	    }
	    else
	    {
	    	fout<<(x*(c/d))<<' '<<(y*(c/d));
	    }
	    fout<<'\n';
	}
	fin.close();
	fout.close();
	return 0;


}