Pagini recente » Cod sursa (job #2419200) | Cod sursa (job #1642925) | Cod sursa (job #572534) | Cod sursa (job #1967512) | Cod sursa (job #2226210)
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int euclid(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = euclid(b, a % b, x0, y0);
x = y0;
y = x0 - a / b * y0;
return d;
}
int main(int argc, char const *argv[]) {
ifstream inFile;
inFile.open("euclid3.in");
ofstream outf("euclid3.out");
int nums, a, b, c, x, y;
inFile >> nums;
for (int i = 0; i < nums; ++i) {
inFile >> a >> b >> c;
int d = euclid(a, b, x, y);
if (c % d != 0) {
outf << "0 0\n";
} else {
outf << x* (c/d) << " " << y*(c/d) << "\n";
}
}
outf.close();
inFile.close();
return 0;
}