Pagini recente » Cod sursa (job #80547) | Cod sursa (job #350096) | Cod sursa (job #364086) | Cod sursa (job #636940) | Cod sursa (job #818972)
Cod sursa(job #818972)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int euclid (int a, int b)
{
if(a<0)
a=-a;
if(b<0)
b=-b;
while(a && b)
{
if(a>b)
a=a%b;
else
b=b%a;
}
return max(a,b);
}
int main ()
{
short t;
int a,b,c,d,i,j;
fin>>t;
for(t;t>0;t--)
{
fin>>a>>b>>c;
d=euclid(a,b);
if(c%d!=0)
fout<<0<<" "<<0<<endl;
else
{
a=a/d;
b=b/d;
c=c/d;
for(i=1;i<d*c;i++)
{
for(j=1;j<d*c;j++)
{
if(i*a+j*b==c)
{
fout<<i<< " "<<j<<endl;
goto loop1;
}
if(i*a-j*b==c)
{
fout<<i<< " "<<-j<<endl;
goto loop1;
}
if(-i*a+j*b==c)
{
fout<<-i<< " "<<j<<endl;
goto loop1;
}
if(-i*a-j*b==c)
{
fout<<-i<< " "<<-j<<endl;
goto loop1;
}
}
}
}
loop1:;
}
}