Pagini recente » Cod sursa (job #1128250) | Cod sursa (job #1239898) | Cod sursa (job #1134222) | Cod sursa (job #1121312) | Cod sursa (job #1239482)
//
// main.cpp
// euclid3
//
// Created by Hai Tran Bach on 10/8/14.
// Copyright (c) 2014 Hai Tran Bach. All rights reserved.
//
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("euclid3.in");
ofstream out("euclid3.out");
int gcd(int a, int b, int &x, int &y) {
if (!b) {
x = 1;
y = 0;
return a;
}
else {
int val = gcd(b, a % b, x, y);
y = x - (a / b) * (x = y);
return val;
}
}
int main() {
int nr = 0, a = 0, b = 0, c = 0, x = 0, y = 0, temp = 0;
in >> nr;
for (int i = 0; i < nr; ++i) {
in >> a >> b >> c;
temp = gcd(a, b, x, y);
if (c % temp == 0) {
out << c / temp * x << " " << c / temp * y << "\n";
}
else {
out << "0 0 \n";
}
}
return 0;
}