Pagini recente » Cod sursa (job #1761506) | Cod sursa (job #1758102) | Cod sursa (job #522668) | Cod sursa (job #2384839) | Cod sursa (job #2177474)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int euclid_extins(int a, int b, int &x, int &y) {
if (!b) {
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = euclid_extins(b, a%b, x0, y0);
x = y0;
y = x0 - (a / b)*y0;
return d;
}
int main() {
int n, a, b, c;
fin >> n;
while (n--) {
fin >> a >> b >> c;
int x, y, d;
d = euclid_extins(a, b, x, y);
if (!(c%d)) {
fout << x*(c / d) << ' ' << y*(c / d) << endl;
}
else {
fout << 0 << ' ' << 0 << endl;
}
}
fout.close();
return 0;
}