Pagini recente » Cod sursa (job #419567) | Cod sursa (job #536246) | Cod sursa (job #2503899) | Cod sursa (job #814080) | Cod sursa (job #2867207)
#include <fstream>
using namespace std;
ifstream fin ("euclid3.in");
ofstream fout ("euclid3.out");
int t;
int a, b, c;
int euclid_E(int a, int b, int &x, int &y);
int main()
{
int x, y;
fin >> t;
while (t--)
{
fin >> a >> b >> c;
int d = euclid_E(a, b, x, y);
if (c % d == 0)
fout << x * (c / d) << ' ' << y * (c / d) << '\n';
else
fout << "0 0\n";
}
return 0;
}
int euclid_E(int a, int b, int &x, int &y)
{
if (b == 0)
{
x = 1;
y = 0;
return a;
}
int x1, y1;
int d = euclid_E(b, a%b, x1, y1);
x = y1;
y = (x1 - y1*(a/b));
return d;
}