Pagini recente » Cod sursa (job #910606) | Cod sursa (job #2300794) | Cod sursa (job #932500) | Cod sursa (job #2331510) | Cod sursa (job #313904)
Cod sursa(job #313904)
#include<stdio.h>
#include<stdlib.h>
int a,b,c,*d,*x,*y,n;
void euclid(int a, int b, int *d, int *x, int *y)
{
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
} else {
int x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main(void)
{
freopen("euclid3.in","r",stdin);
freopen("euclid3.out","w",stdout);
x=malloc(4); y=malloc(4);
d=malloc(4);
scanf("%d",&n);
int i;
for(i=1; i<=n; i++){
scanf("%d %d %d",&a,&b,&c);
euclid(a,b,d,x,y);
int rest;
rest=*d;
int rez=c/rest;
int aux=*x;
aux*=rez;
*x=aux;
aux=*y;
aux*=rez; *y=aux;
if(*x && *y)
printf("%d %d\n",*x,*y);
else printf("0 0\n");
}
return 0;
}