Pagini recente » Cod sursa (job #2834658) | Cod sursa (job #222943) | Cod sursa (job #2311041) | Cod sursa (job #1491899) | Cod sursa (job #2171620)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int eec(int a, int b, long long &x, long long &y)
{
if (a % b == 0)
{
x = 0;
y = 1;
return b;
}
long long x2;
int cmmdc = eec(b, a % b, x2, x);
y = x2 - x * (a / b);
return cmmdc;
}
int main()
{
int T, a, b, c, d;
long long x, y;
fin >> T;
while (T--)
{
bool invers = false;
fin >> a >> b >> c;
if (b == 0)
{
d = a;
x = 1; y = 0;
}
else
d = eec(a, b, x, y);
if (c % d != 0)
{
fout << "0 0\n";
continue;
}
fout << x * c / d << ' ' << y * c / d << '\n';
}
}