Pagini recente » Cod sursa (job #2867370) | Cod sursa (job #837463) | Cod sursa (job #2670231) | Cod sursa (job #588101) | Cod sursa (job #2171522)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void eec(int a, int b, int c, int &x, int &y)
{
if (a % b == c)
{
x = 1;
y = - (a / b);
return;
}
if (a % b == 0)
{
x = 0;
y = 0;
return;
}
int x2;
eec(b, a % b, c, x2, x);
y = x2 - x * (a / b);
}
int main()
{
int T, a, b, c, x, y;
fin >> T;
while (T--)
{
bool invers = false;
fin >> a >> b >> c;
if (a < b)
{
swap(a, b);
invers = true;
}
eec(a, b, c % a, x, y);
if (x != 0 && y != 0)
{
x += c / a;
if (invers)
swap(x, y);
fout << x << ' ' << y << '\n';
}
else
fout << "0 0\n";
}
}