Cod sursa(job #616581)

Utilizator RuxyRezidentTMRuxandra P RuxyRezidentTM Data 12 octombrie 2011 21:27:58
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.65 kb
/*
 * euclid3.cpp
 *
 *  Created on: Oct 11, 2011
 *      Author: ruxy
 */

#include<fstream>
using namespace std;

ifstream f("euclid3.in");
ofstream g("euclid3.out");


long long x0, y0,x,y,d;

void calcul(long long a,long long b) {
	if (b == 0) {
		d = a;
		x0 = 1;
		y0 = 0;
	} else {
		calcul( b, a % b);
		x = y0;
		y = x0 - (a / b) * y0;
		x0=x;
		y0=y;
	}
}

int main() {
	int T,i;
	long long a,b,c;
	f>>T;
	for(i=1;i<=T;i++)
	{
	 	f >> a;
        f >> b;
        f >> c;
	calcul( a, b);
	float div = (float)c / d;
	if ((c / d) == div)
		{x = x * (c / d);
	     y = y * (c / d);
	     g << x << ' ' << y<<' ';
		}
	else g<<"0 0";
	g<<'\n';

	}
	return 0;
}