Pagini recente » Cod sursa (job #1394634) | Cod sursa (job #2491359) | Cod sursa (job #1394626)
#include <fstream>
#include <iostream>
using namespace std;
void extendedEuclid(int a, int b, int *c, int *x, int *y) {
// cout << a << " " << b << " " << *c << endl;
if (b == 0) {
*x = (*c) % a == 0 ? 1 : 0;
*c = *c / a;
*y = 0;
return;
}
int x0{0}, y0{0};
extendedEuclid(b, a % b, c, &x0, &y0);
// cout << x0 << " " << y0 << endl;
if (x0 != 0 || y0 != 0) {
*y = x0 - a / b * y0;
*x = y0;
}
}
int main(int argc, char *argv[])
{
ifstream f{"euclid3.in"};
ofstream g{"euclid3.out"};
// to check c % cmmdc(a, b)
int n, a, b, c;
f >> n;
for (int i = 0; i < n; ++i) {
f >> a >> b >> c;
int x{0}, y{0};
extendedEuclid(a, b, &c, &x, &y);
g << x * c << " " << y * c<< "\n";
// cout << endl << endl;
}
return 0;
}