Pagini recente » Cod sursa (job #3299652) | Cod sursa (job #1773697) | Cod sursa (job #2100511) | Cod sursa (job #1773723) | Cod sursa (job #3299648)
#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;
FILE *input = fopen("euclid3.in", "r");
FILE *output = fopen("euclid3.out", "w");
if (!input || !output) {
fprintf(stderr, "Eroare deschidere fisiere!");
exit(-1);
}
if (fscanf(input, "%ld %ld %ld", &a, &b, &c) != 3) {
fprintf(stderr, "Eroare la citire a, b, c!\n");
exit(-1);
}
long g = exeuclid(a, b, &x, &y);
if (g % c != 0) {
fprintf(output, "Nu exista solutie\n");
} else {
fprintf(output, "%ld %ld\n", x * (c / g), y * (c / g));
}
fclose(input);
fclose(output);
return 0;
}