Pagini recente » Cod sursa (job #2324768) | Cod sursa (job #1561832) | Cod sursa (job #1643539) | Cod sursa (job #1452824) | Cod sursa (job #2808863)
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream gout("euclid3.out");
void euclid(long long a, long long b, long long *d, long long *x, long long *y)
{
if(b==0)
{
*x=1;
*y=0;
*d=a;
}
else
{
long long x0,y0;
euclid(b,a%b,d,&x0,&y0);
*x=y0;
*y=x0-(a/b)*y0;
}
}
int main()
{
long long a,b,c,d,x,y,ok=1,n;
fin>>n;
while(n)
{
fin>>a>>b>>c;
ok=1;
if(a<b)
{
swap(a,b);
ok=0;
}
euclid(max(a,b),min(a,b),&d,&x,&y);
///cout<<x<<" "<<y<<" "<<d<<endl;
if(c%d!=0)
gout<<0<<" "<<0;
else
{
x=x*c/d;
y=y*c/d;
if(ok==1)
gout<<x<<" "<<y<<" "<<d<<endl;
else
gout<<y<<" "<<x<<" "<<d<<endl;
n--;
}
}
return 0;
}