Pagini recente » Cod sursa (job #814569) | Cod sursa (job #3133462) | Cod sursa (job #996540) | Cod sursa (job #1454071) | Cod sursa (job #3317833)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
void euclid(int a, int &x, int b, int &y, int &d)
{
if (b == 0)
{
x = 1;
y = 0;
d = a;
return;
}
int x0, y0;
euclid(b, x0, a % b, y0, d);
x = y0;
y = x0 - (a / b) * y0;
}
int main()
{
int n, a, b, c;
fin >> n;
for (int i = 1; i <= n; i++)
{
int cInitial;
fin >> a >> b >> c;
cInitial = c;
int x, y;
euclid(a, x, b, y, c);
/// la final, c va contine cmmdc(a,b)
/// noi vom avea doua numere x si y astfel incat a * x + b * y = cmmdc(a,b)
if (cInitial % c != 0)
{
/// numerele nu au niste coeficienti care sa dea rezultatul cInitial
fout << 0 << ' ' << 0 << '\n';
}
else
fout << 1LL * x * cInitial / c << " " << 1LL * y * cInitial / c << '\n';
}
return 0;
}