Pagini recente » Cod sursa (job #2456723) | Cod sursa (job #2214823) | Cod sursa (job #2705205) | Cod sursa (job #1701472) | Cod sursa (job #1701474)
#include <fstream>
#include <cmath>
using namespace std;
ifstream in ("euclid3.in");
ofstream out ("euclid3.out");
int euclid (int a, int b, int &x, int &y)
{
if(b == 0)
{
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = euclid (b, a % b, x0, y0);
x = y0;
y = x0 - a / b * x;
return d;
}
int main()
{
int a, b, c, t, i, d, x, y;
in >> t;
for(i = 1; i <= t; i ++)
{
in >> a >> b >> c;
if(a < b) d = euclid (b, a, y, x);
else d = euclid (a, b, x, y);
if (c % d != 0) out << "0 0\n";
else out << x * c / d << " " << y * c / d << "\n";
}
return 0;
}