Pagini recente » Cod sursa (job #1391907) | Cod sursa (job #380357) | Cod sursa (job #12273) | Cod sursa (job #189609) | Cod sursa (job #2663393)
#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)
{
x = 1;
y = 0;
d = a;
return;
}
int xx, yy, q = a / b;
euclid_extins(b, a % b, xx, yy, d);
x = yy;
y = xx - q * yy;
}
int main()
{
int t;
in >> t;
for (int i = 0; i < t; i++)
{
int a, b, c, x, y, d;
in >> a >> b >> c;
euclid_extins(a, b, x, y, d);
if (c % d == 0)
{
out << c/d * x << " " << c/d * y << "\n";
}
else
{
out << "0 0\n";
}
}
in.close();
out.close();
return 0;
}