Pagini recente » Cod sursa (job #127739) | Monitorul de evaluare | Cod sursa (job #304299) | Profil eugen_cutic | Cod sursa (job #2280464)
#include <bits/stdc++.h>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
void euclidExtins(int a, int b, int &d, int &x, int &y) {
if(b == 0) {
d = a;
x = 1;
y = 0;
} else {
int x0, y0;
euclidExtins(b, a % b, d, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
}
}
int main() {
ios::sync_with_stdio(false); in.tie(0); out.tie(0);
int t; in >> t;
while(t--) {
int a, b, c; in >> a >> b >> c;
int x, y, d;
euclidExtins(a, b, d, x, y);
if(c % d) {
out << "0 0\n";
} else {
int alpha = c / d;
out << alpha * x << " " << alpha * y << "\n";
}
}
in.close(); out.close();
return 0;
}