Pagini recente » Cod sursa (job #3350897) | Cod sursa (job #3326985)
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
ifstream f("euclid3.in");
ofstream g("euclid3.out");
int gcd(int a, int b, int &x, int &y) {
if (!b) {
x = 1;
y = 0;
return a;
}
int x0, y0, d;
d = gcd(b, a % b, x0, y0);
x = y0;
y = x0 - (a / b) * y0;
return d;
}
void solve() {
int a, b, c, x, y;
f >> a >> b >> c;
int d = gcd(a, b, x, y);
if (c % d)
g << 0 << " " << 0;
else
g << x * (c / d) << " " << y * (c / d);
}
int main() {
int cases;
f >> cases;
while (cases--) {
solve();
g << "\n";
}
return 0;
}