Pagini recente » Cod sursa (job #905802) | Borderou de evaluare (job #403787) | Cod sursa (job #2702392)
#include <bits/stdc++.h>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
void solve();
int cmmdc(int, int, int &, int &);
int main()
{
int t;
for (f >> t; t; t--)
solve();
return 0;
}
void solve()
{
int a, b, c, x, y;
f >> a >> b >> c;
int d = cmmdc(a, b, x, y);
if (c % d)
g << "0 0\n";
else
g << 1ll * x * (c / d) << " " << 1ll * y * (c / d) << '\n';
}
int cmmdc(int a, int b, int &x, int &y)
{
if (!b)
{
y = 0;
x = 1;
return a;
}
int x0, y0;
int d = cmmdc(b, a % b, x0, y0);
x = y0;
y = x0 - 1ll * (a / b) * y0;
return d;
}