Pagini recente » Cod sursa (job #2629144) | Cod sursa (job #1754409) | Cod sursa (job #919652) | Cod sursa (job #888775) | Cod sursa (job #230128)
Cod sursa(job #230128)
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
void euclid(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return;
}
euclid(b, a%b, x, y);
int X, Y;
X = y;
Y = x - (a / b) * y;
x = X; y = Y;
}
int main() {
ifstream fin("euclid3.in");
ofstream fout("euclid3.out");
int n;
fin >> n;
while (n--) {
int a, b, d;
fin >> a >> b >> d;
if (d % __gcd(a, b)) {fout << "0 0\n"; continue;}
int M = d /__gcd(a, b);
int x, y;
euclid(a, b, x, y);
x*=M; y*=M;
fout << x << " " << y << '\n';
}
return 0;
}