Pagini recente » Rating PLOSNITA ANDRA LAVINIA (laviniap) | tema | Monitorul de evaluare | Cod sursa (job #3299649)
#include <stdio.h>
#include <stdlib.h>
long exeuclid(long a, long b, long *x, long *y) {
if (b == 0) {
*x = 1;
*y = 0;
return a;
}
long x1, y1;
long g = exeuclid(b, a % b, &x1, &y1);
*x = y1;
*y = x1 - (a / b) * y1;
return g;
}
int main() {
long a, b, c, x, y, t, i;
FILE *input = fopen("euclid3.in", "r");
FILE *output = fopen("euclid3.out", "w");
if (!input || !output) {
fprintf(stderr, "Eroare deschidere fisiere!\n");
return 1;
}
if (fscanf(input, "%ld", &t) != 1) {
fprintf(stderr, "Eroare la citire t!\n");
return 1;
}
for (i = 0; i < t; ++i) {
if (fscanf(input, "%ld %ld %ld", &a, &b, &c) != 3) {
fprintf(stderr, "Eroare la citire a, b, c!\n");
return 1;
}
long g = exeuclid(a, b, &x, &y);
if (g == 0 || c % g != 0)
fprintf(output, "0 0\n");
else
fprintf(output, "%ld %ld\n", x * (c / g), y * (c / g));
}
fclose(input);
fclose(output);
return 0;
}