Pagini recente » Cod sursa (job #2728938) | Cod sursa (job #3286375) | Cod sursa (job #2176919) | Cod sursa (job #143712) | Cod sursa (job #143725)
Cod sursa(job #143725)
# include <stdio.h>
# define input "euclid3.in"
# define output "euclid3.out"
long a,b,c,T;
void calc(long a,long b,long &d,long &x,long &y)
{
if(b == 0)
{
x = 1;
y = 0;
d = a;
}
else
{
long x0,y0;
calc(b,a%b,d,x0,y0);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main()
{
freopen(input, "r", stdin);
freopen(output, "w",stdout);
scanf("%ld",&T);
while(T)
{
scanf("%ld%ld%ld",&a,&b,&c);
long x,y,d;
calc(a,b,d,x,y);
if(c%d != 0)
printf("0 0\n");
else
printf("%ld %ld\n",x*(c/d),y*(c/d));
T--;
}
return 0;
}