Pagini recente » Cod sursa (job #1199877) | Cod sursa (job #372626) | Cod sursa (job #2478747) | Cod sursa (job #1100767) | Cod sursa (job #155203)
Cod sursa(job #155203)
#include <stdio.h>
long cmmdc_extins(long a, long b, long &x, long &y) {
if (!b) {
x = 1;
y = 0;
return a;
}
long x0, y0;
long d = cmmdc_extins(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
int main() {
freopen("euclid3.in", "r",stdin);
freopen("euclid3.out", "w",stdout);
long T;
scanf("%ld", &T);
for (long i = 0; i < T; i ++) {
long a, b, d, c;
scanf("%ld %ld %ld", &a, &b, &c);
long x = 1, y = 0;
d = cmmdc_extins(a, b, x, y);
if (c % d) {
printf("0 0 0\n");
continue;
}
x *= c/d;
y *= c/d;
printf("%ld %ld\n", x, y);
}
fclose(stdin);
fclose(stdout);
return 0;
}