Pagini recente » Cod sursa (job #3200452) | Cod sursa (job #281100) | Clasament fgh | Cod sursa (job #2971582) | Cod sursa (job #2745553)
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
void euclid_extins(int a, int b, int &x, int &y, int &d)
{
if (b == 0)
{
d = a;
x = 1;
y = 0;
return;
}
int xx, yy, q = a / b;
euclid_extins(b, a % b, xx, yy, d);
x = yy;
y = xx - yy * q;
}
int main()
{
int t;
in >> t;
for (int i = 0; i < t; i++)
{
int a, b, c, d, x, y;
in >> a >> b >> c;
euclid_extins(a, b, x, y, d);
if (c % d == 0)
{
out << x * (c/d) << " " << y * (c/d) << "\n";
}
else
{
out << "0 0\n";
}
}
in.close();
out.close();
return 0;
}