Pagini recente » Cod sursa (job #1878880) | Cod sursa (job #142859) | Cod sursa (job #616527) | Cod sursa (job #1968353) | Cod sursa (job #2595998)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int t, a, b, c, d, x, y;
int euclid_extins(int a, int b, int &x, int &y)
{
int d, x0, y0;
if(!b)
{
x = 1;
y = 0;
return a;
}
else
{
d = euclid_extins(b, a % b, x0, y0);
x = y0;
y = x0 - a / b * y0;
return d;
}
}
int main()
{
f >> t;
while(t)
{
f >> a >> b >> c;
d = euclid_extins(a, b, x, y);
if(c % d)
g << "0 0\n";
else
g << c / d * x << ' ' << c / d * y << '\n';
t--;
}
f.close();
g.close();
return 0;
}