Pagini recente » Cod sursa (job #3357758) | Cod sursa (job #3358857) | Cod sursa (job #3358480) | Cod sursa (job #3328452) | Cod sursa (job #3358326)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid(long long a,long long b, long long &d, long long &x, long long &y)
{
if (b == 0) {
d = a;
x = 1;
y = 0;
} else {
long long x0, y0;
euclid(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main()
{
int t;
long long a,b,c;
fin>>t;
for(int i=1;i<=t;i++){
fin>>a>>b>>c;
if(a==0 && b==0){
fout<<a<< " "<<b<< '\n';
continue;
}
long long d,x,y;
euclid(a,b,d,x,y);
if(d<0){
d=-d;
x=-x;
y=-y;
}
if(c%d == 0){
fout<<x*(c/d)<< " "<<y*(c/d)<< '\n';
}
else{
fout<<0<< " "<<0<< '\n';
}
}
fin.close();
fout.close();
return 0;
}