Cod sursa(job #3325627)

Utilizator CosminaneBoac Mihai Cosmin Cosminane Data 25 noiembrie 2025 21:04:15
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.57 kb
#include <fstream>
using namespace std;
int cmmdc( int a, int b, int &x, int &y ){
	int x0, y0, d;
	if( b == 0 ){
		x = 1;
		y = 0;
		return a;
	}
	d = cmmdc( b, a % b, x0, y0 );
	x = y0;
	y = x0 - a / b * y0;
	return d;
}
int main(){
	int t, i, a, b, c, d, x, y;
	ifstream fin( "euclid3.in" );
	ofstream fout( "euclid3.out" );
	fin >> t;
	for( i = 0; i < t; i++ ){
		fin >> a >> b >> c;
		d = cmmdc( a, b, x, y );
		if( c % d != 0 ){
			fout << 0 << ' ' << 0 << '\n';
		}
		else{
			fout << c / d * x << ' ' << c / d * y << '\n';
		}
	}
	return 0;
}