Pagini recente » Cod sursa (job #507132) | Clasamentul arhivei de probleme | Cod sursa (job #462288) | Cod sursa (job #445312) | Cod sursa (job #1427978)
#include <stdio.h>
#include <stdlib.h>
FILE * open_file(const char * file, const char * opt)
{
FILE * f = fopen(file, opt);
if(f == NULL)
{
perror("Eroare");
exit(EXIT_FAILURE);
}
return f;
}
char s;
int c, d;
void solve(int a, int b, int *x , int *y)
{
int x0, y0;
if(b == 0)
{
*x = 1;
*y = 0;
if(c % a != 0)
{
s = 0;
}
d = a;
return;
}
solve(b, a%b, &x0, &y0);
*x = y0;
*y = x0 - (a/b) * y0;
}
int main()
{
FILE *in = open_file("euclid3.in", "r");
FILE *out = open_file("euclid3.out", "w");
int n, a, b;
int x, y;
fscanf(in, "%d", &n);
while(n--)
{
fscanf(in, "%d%d%d", &a, &b, &c);
s = 1;
solve(a, b, &x, &y);
if(s == 1)
{
fprintf(out,"%d %d\n", x * (c/d), y*(c/d));
}
else
{
fprintf(out, "0 0\n");
}
}
fclose(in);
fclose(out);
return 0;
}