Pagini recente » Cod sursa (job #604230) | Cod sursa (job #1679218) | Cod sursa (job #1533257) | Cod sursa (job #1616983) | Cod sursa (job #2214055)
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int cmmdc(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int ans = cmmdc(b, a % b, x, y);
int aux = x;
x = y;
y = aux - (y * (a / b));
return ans;
}
int a, b, c, x, y;
int n;
int main() {
in >> n;
while (n --) {
in >> a >> b >> c;
x = y = 0;
int d = cmmdc(a, b, x, y);
out << d << ' ';
if (c % d == 0)
out << x * c / d << ' ' << y * c / d << '\n';
else
out << "0 0\n";
}
return 0;
}