Cod sursa(job #1459282)

Utilizator Vlad_lsc2008Lungu Vlad Vlad_lsc2008 Data 9 iulie 2015 15:25:42
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.67 kb
#include <iostream>
#include <fstream>
#define fin "euclid3.in"
#define fou "euclid3.out"
using namespace std;
ifstream t1(fin);
ofstream t2(fou);
int a,b,c,x,y;

int euclidextins(int a, int b,int &x,int &y)
{
	if(b==0)
    {
        x=1;
        y=0;
        return a;
    }
	else
    {
        int x0,y0,d;
        d=euclidextins(b, a % b,x0,y0);
        x=y0;
        y=x0-(a/b)*y0;
        return d;
    }
}

int main()
{
	int n,i,x,y,d;
	t1 >> n;
	for (i = 1; i <= n;i++)
	{
		t1>>a>>b>>c;
        d=euclidextins(a,b,x,y);
        if(c%d) t2<<"0 0"<<'\n';
        else t2<<x*(c/d)<<' '<<y*(c/d)<<'\n';
	}
	t1.close();
	t2.close();
	return 0;
}