Pagini recente » Cod sursa (job #2145525) | Cod sursa (job #95586) | Cod sursa (job #2389647) | Cod sursa (job #1547811) | Cod sursa (job #2886733)
#include <iostream>
#include <fstream>
using namespace std;
const string filename = "euclid3";
ifstream fin(filename + ".in");
ofstream fout(filename + ".out");
void euclid_extins(int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return;
}
euclid_extins(b, a % b, x, y);
int xprim = x, yprim = y;
x = yprim;
y = xprim - (a / b) * yprim;
}
void solve()
{
bool swapped = 0;
int a, b, c = 0, d, x = 0, y = 0;
fin >> a >> b >> d;
if(a < b)
{
swap(a, b);
swapped = 1;
}
euclid_extins(a, b, x, y);
c = a * x + b * y;
if(d % c != 0)
{
fout << "0 0\n";
return;
}
x = x * d / c;
y = y * d / c;
if(swapped)
swap(x, y);
fout << x << ' ' << y << '\n';
}
int main()
{
int nr_teste;
fin >> nr_teste;
while(nr_teste--)
solve();
return 0;
}