Pagini recente » Cod sursa (job #2108590) | Cod sursa (job #1615058) | Cod sursa (job #1892837) | Cod sursa (job #2942777) | Cod sursa (job #1338375)
#include <fstream>
#include <algorithm>
#define infile "euclid3.in"
#define outfile "euclid3.out"
using namespace std;
ifstream f(infile);
ofstream g(outfile);
int euclid(int a, int b, int &x, int &y) {
if (!b) {
x = 1;
y = 0;
return a;
}
int xa, ya;
int d = euclid(b, a%b, xa, ya);
x = ya;
y = xa - (a / b)*ya;
return d;
}
int main() {
int tests;
f >> tests;
for (; tests; --tests) {
int a, b, c, x, y;
f >> a >> b >> c;
int d = euclid(a, b, x, y);
if (c % d != 0) {
g << "0 0\n";
continue;
}
x *= (c / d);
y *= (c / d);
g << x << ' ' << y << '\n';
}
return 0;
}
//Trust me, I'm the Doctor!