Cod sursa(job #1207065)

Utilizator thesilverhand13FII Florea Toma Eduard thesilverhand13 Data 12 iulie 2014 00:56:33
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.71 kb
# include <fstream>
# include <algorithm>
# include <cstring>
# include <vector>

using namespace std;

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

int n;
int a, b, c, t;

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

int main(){
	
	int i, x, y, d = 0;
	f >> t;
	for ( i = 1 ; i <= t ; i++ ){
		f >> a >> b >> c;
		euclid( a, b, d, x, y );
		//g << x << " " << y << " " << d << "\n";
		if (   c % d  == 0  )
			g << x * ( c / d ) << " " << y * ( c / d ) << "\n";
		else
			g << 0 << " " << 0 << "\n";
		
 	}
	return 0;
}