Pagini recente » Cod sursa (job #604196) | Cod sursa (job #1978838) | Cod sursa (job #1963122) | Cod sursa (job #1540527) | Cod sursa (job #2039579)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid(int,int,int*,int*,int*);
int main() {
int n;
fin>>n;
while(n--) {
int a, b, c, cmmdc, x, y;
fin>>a>>b>>c;
euclid(a, b, &cmmdc, &x, &y);
cout<<cmmdc<<' ';
if(c % cmmdc != 0) {
fout<<"0 0\n";
continue;
} else {
fout<<x * (c / cmmdc)<<' '<<y * (c / cmmdc)<<'\n';
}
}
fin.close();
fout.close();
return 0;
}
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);
*y = x0 - y0 * (a / b);
*x = y0;
}
}