Pagini recente » Cod sursa (job #947277) | Cod sursa (job #1740093) | Cod sursa (job #2785587) | Cod sursa (job #1928416) | Cod sursa (job #3357379)
#include <stdio.h>
#include <stdlib.h>
void euclid(long long a, long long b, long long *d, long long *x, long long *y)
{
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
} else {
long long x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main(void)
{
FILE *in, *out;
in = fopen("euclid3.in", "r");
if(in == NULL)
{
printf("eroare deschidere fisier\n");
exit(EXIT_FAILURE);
}
out = fopen("euclid3.out", "w");
if(out == NULL)
{
printf("eroare deschidere fisier\n");
exit(EXIT_FAILURE);
}
int n;
if(fscanf(in, "%d", &n) != 1)
{
printf("eroare citire fisier\n");
exit(EXIT_FAILURE);
}
for(int i = 0; i < n; i++)
{
long long a, b, c;
if(fscanf(in, "%lld %lld %lld", &a, &b, &c) != 3)
{
printf("eroare citire fisier\n");
exit(EXIT_FAILURE);
}
long long x, y, d;
euclid(a, b, &d, &x, &y);
if(c%d == 0)
fprintf(out, "%lld %lld\n", x*(c/d), y*(c/d));
else
fprintf(out, "0 0\n");
}
if(fclose(in) != 0)
{
printf("eroare inchidere fisier\n");
exit(EXIT_FAILURE);
}
if(fclose(out) != 0)
{
printf("eroare inchidere fisier\n");
exit(EXIT_FAILURE);
}
return 0;
}