Pagini recente » Cod sursa (job #485798) | Cod sursa (job #2334645) | Istoria paginii runda/crcs_78/clasament | Cod sursa (job #1469747) | Cod sursa (job #2208052)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void Read(int& size, vector <int>& equations)
{
int prop;
fin >> size;
while (fin >> prop)
{
equations.push_back(prop);
}
}
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) * y0;
return d;
}
int main(void)
{
int size, c = 0;
vector <int> equations;
Read(size, equations);
int x, y, d = 0;
for (int i = 0; i < size; i++)
{
d = euclid(equations.at(3 * i), equations.at(3 * i + 1), x, y);
c = equations.at(3 * i + 2);
if (c % d)
{
fout << "0 0\n";
}
else
{
fout << x * (c / d) << ' ' << y * (c / d) << '\n';
}
}
return 0;
}