Pagini recente » Cod sursa (job #2316721) | Cod sursa (job #2344439) | Cod sursa (job #2549227) | Cod sursa (job #3187565) | Cod sursa (job #2113683)
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
void euclidextins(int a, int b, int &x, int &y, int &d)
{
if (!b)
{
x = 1;
y = 0;
d = a;
}
else
{
int x0, y0;
euclidextins(b, a%b, x0, y0, d);
x = y0;
y = x0 - (a / b)*y0;
}
}
int main()
{
int n, a, b, c, d, x, y;
in >> n;
while (n)
{
in >> a >> b >> c;
euclidextins(a, b, x, y, d);
if (c%d == 0)
{
out << x * (c / d) <<' '<< y * (c / d)<<'\n';
}
else out << 0 <<' '<< 0<<'\n';
n--;
}
return 0;
}