Pagini recente » tema | Cod sursa (job #1455994) | Cod sursa (job #2333006) | Sandbox (cutiuţa cu năsip) | Cod sursa (job #964561)
Cod sursa(job #964561)
#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;
}