Pagini recente » Cod sursa (job #536863) | Cod sursa (job #1675350) | Cod sursa (job #3174708) | Cod sursa (job #1744960) | Cod sursa (job #2964277)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int cmmdc(int a, int b, int& x, int& y)
{
if(!b)
{
x=1, y=0;
return a;
}
int xx, yy, d;
d=cmmdc(b, a%b, xx, yy);
x=xx;
y=xx-(a/b)*yy;
return d;
}
void testCase()
{
int a, b, c, x, y;
fin>>a>>b>>c;
int d=cmmdc(a, b, x, y);
if(c%d)
fout<<"0 0"<<'\n';
else fout<<x*(c/d)<<' '<<y*(c/d)<<'\n';
}
int T;
int main()
{
ios_base::sync_with_stdio(false);
fin.tie(0);
fin>>T;
for(int i=0; i<T; i++)
testCase();
fin.close();
fout.close();
return 0;
}