Pagini recente » Cod sursa (job #829204) | Cod sursa (job #2436162)
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int a, b, d, x, y, n;
void euclid(int a, int b, int* d, int* x, int* y)
{
if (b == 0) {
*d = a;
*x = 1;
*y = 0;
}
else {
int x0, y0;
euclid(b, a % b, d, &x0, &y0);
*x = y0;
*y = x0 - (a / b) * y0;
}
}
int main()
{
f >> n;
for (int i = 0; i < n; i++)
{
int c, n, x0, y0;
f >> a >> b >> c;
euclid(a, b, &d, &x, &y);
if (c % d != 0)
{
g << 0 << " " << 0 << "\n";
}
else
{
n = c / d;
x0 = x * n;
y0 = y * n;
g << x0 << " " << y0 << "\n";
}
}
}