Pagini recente » Cod sursa (job #1785706) | Cod sursa (job #479913) | Cod sursa (job #1344584) | Cod sursa (job #2376802) | Cod sursa (job #359709)
Cod sursa(job #359709)
// euclid3.cpp : Defines the entry point for the console application.
//
#include <cstdio>
void euclid(int a,int b,int *x,int *y)
{
if(b==0)
{
*x=1;
*y=0;
}
else
{
int x0,y0;
euclid(b,a%b,&x0,&y0);
*x=y0;
*y=x0-a/b*y0;
}
}
int cmmdc(int a,int b)
{
int r;
while(b)
{
r=a%b;
a=b;
b=r;
}
return a;
}
int main()
{
int t,a,b,c;
freopen("euclid3.in","r",stdin);
freopen("euclid3.out","w",stdout);
scanf("%d",&t);
for(int i=1;i<=t;i++)
{
int x,y,d;
scanf("%d %d %d",&a,&b,&c);
d=cmmdc(a,b);
euclid(a,b,&x,&y);
if(c%d==0)
printf("%d %d\n",x*(c/d),y*(c/d));
else
printf("0 0\n");
}
return 0;
}