Pagini recente » Cod sursa (job #1520044) | Cod sursa (job #172636) | Cod sursa (job #463145) | Cod sursa (job #484469) | Cod sursa (job #2900531)
#include <fstream>
using namespace std;
#define int long long
const string filename = "euclid3";
ifstream fin(filename + ".in");
ofstream fout(filename + ".out");
/// x0 * b + y0 * (a - (a/b) * b) = c
/// x * a + y * b = c
/// x * a + y * b = y0 * a + x0 * b - y0 * (a / b) * b;
void big_euclid(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return;
}
big_euclid(b, a % b, x, y);
int x0 = x, y0 = y;
x = y0;
y = x0 - y0 * (a / b);
}
signed main()
{
int nr_teste;
fin >> nr_teste;
while(nr_teste--)
{
int a, b, c, d, x = 0, y = 0;
bool swapped = 0;
fin >> a >> b >> d;
if(a > b)
{
swap(a, b);
swapped = 1;
}
big_euclid(a, b, x, y);
c = a * x + b * y;
if(d % c != 0)
fout << "0 0\n";
else
{
if(swapped)
swap(x, y);
x *= d/c;
y *= d/c;
fout << x << ' ' << y << '\n';
}
}
return 0;
}