Pagini recente » Cod sursa (job #1208443) | Cod sursa (job #3270583) | Cod sursa (job #1804477) | Cod sursa (job #1629476) | Cod sursa (job #1889123)
#include <cstdio>
using namespace std;
auto fin = fopen("euclid3.in", "r");
auto fout = fopen("euclid3.out", "w");
int euclid(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int xprev, yprev;
int d = euclid(b, a % b, xprev, yprev);
x = yprev;
y = xprev - (a / b) * yprev;
return d;
}
int main() {
int t;
fscanf(fin, "%d", &t);
while (t--) {
int x, y, a, b, c, d;
fscanf(fin, "%d %d %d", &a, &b, &c);
d = euclid(a, b, x, y);
if (c % d)
fprintf(fout, "0 0\n");
else
fprintf(fout, "%d %d\n", c / d * x, c / d * y);
}
return 0;
}