Cod sursa(job #964561)

Utilizator RoxanaIstrateIstrate Roxana RoxanaIstrate Data 21 iunie 2013 14:42:55
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.56 kb
#include <iostream>
#include <fstream>
using namespace std;

int cmmdc( int fst, int snd, int *X, int *Y){

	int t;
	if (snd == 0){
		*X = 1;
		*Y = 0;
		return fst;
	}
	int x0, y0, d;
	d = cmmdc(snd,fst%snd,&x0,&y0);
	*X = y0;
	*Y = x0 - (fst/snd)*y0;
	return d;

}
int main(){

	ifstream fin("euclid3.in");
	ofstream fout("euclid3.out");
	int tests,i, fst, snd, X, Y, c, eq;
	fin>>tests; 
	for(i = 0; i < tests; i++){
		fin>>fst>>snd>>eq;
		c = cmmdc(fst,snd,&X,&Y);
		if (eq % c){
			fout<<"0 0\n";
		}else{
			fout<<X*(eq/c)<<" "<<Y*(eq/c)<<"\n";
		}
	}
	return 0;
}