Pagini recente » Cod sursa (job #2800678) | Cod sursa (job #652898) | Cod sursa (job #1418558) | Cod sursa (job #2143968) | Cod sursa (job #1291515)
#include <fstream>
using namespace std;
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
inline int extendedgcd(int a, int b, int &x, int &y) {
if(!b) {
x = 1;
y = 0;
return a;
}
int x1, y1;
int ret = extendedgcd(b, a % b, x1, y1);
x = y1;
y = x1 - (a / b) * y1;
return ret;
}
int main() {
int t;
fin >> t;
while (t --) {
int a, b, c;
fin >> a >> b >> c;
int x, y;
int d = extendedgcd(a, b, x, y);
if(c % d) {
fout << "0 0\n";
continue;
}
fout << x * (c / d) << ' ' << y * (c / d) << '\n';
}
}