Pagini recente » Cod sursa (job #1229183) | Cod sursa (job #2122753) | Cod sursa (job #3141504) | Cod sursa (job #1954196) | Cod sursa (job #2848044)
#include <fstream>
using namespace std;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
long int t,a,b,c,k,x,y,d;
void cmmdc (long int a,long int b,long int &d)
{
if (b==0)
d = a;
else
cmmdc(b,a%b,d);
}
void euclid (long int a,long int b,long int &d,long int &x,long int &y)
{
if (b==0)
{
d = a;
x = 1;
y = 0;
}
else
{
long int x0,y0;
euclid(b,a%b,d,x0,y0);
x = y0;
y = x0 - (a/b)*y0;
}
}
int main()
{
fin >> t;
for (k=1; k<=t; k++)
{
fin >> a >> b >> c;
cmmdc(a,b,d);
if (c%d!=0)
{
fout << 0 << ' ' << 0;
}
else
{
euclid(a,b,d,x,y);
fout << x*c/d << ' ' << y*c/d << '\n';
}
}
return 0;
}