Pagini recente » Cod sursa (job #1128169) | Cod sursa (job #1565344) | Cod sursa (job #2025560) | Cod sursa (job #2025556) | Cod sursa (job #1239483)
//
// 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 x1, y1;
int val = gcd(b, a % b, x1, y1);
y = x1 - (a / b) * y1;
x = y1;
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;
}