Pagini recente » Cod sursa (job #2177221) | Cod sursa (job #818517) | Cod sursa (job #1997758) | Cod sursa (job #1652335) | Cod sursa (job #3295451)
#include <stdio.h>
#include <string.h>
int cmmdc(int a, int b, int *x, int *y) {
if(b == 0) {
*x = 1;
*y = 0;
return a;
} else {
int x1, y1;
int d = cmmdc(b, a % b, &x1, &y1);
*x = y1;
*y = x1 - (a / b) * y1;
return d;
}
}
int main() {
FILE *input = fopen("euclid3.in", "r");
FILE *output = fopen("euclid3.out", "w");
int n, a, b, c, d, x, y;
fscanf(input, "%d", &n);
for(int i = 0; i < n; i++) {
fscanf(input, "%d %d %d", &a, &b, &c);
d = cmmdc(a, b, &x, &y);
if(c % d != 0) {
fprintf(output, "0 0\n");
} else {
fprintf(output, "%d %d\n", x * (c / d), y * (c / d));
}
}
fclose(input);
fclose(output);
return 0;
}