Cod sursa(job #2710341)

Utilizator KPP17Popescu Paul KPP17 Data 22 februarie 2021 13:58:51
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include <fstream>
#define mF "euclid3"
std::ifstream in(mF ".in");
std::ofstream out(mF ".out");
#include <tuple>
int x, y; int f(int a, int b)
{
    if (b) {int d = f(b, a % b); std::tie(x, y) = std::make_tuple(y, x-(a/b)*y); return d;}
    x = 1; y = 0; return a;
}
int main()
{
    int n; in >> n; while (n--)
    {
        int a, b, c, d; in >> a >> b >> c; d = f(a, b);
        if (c % d) out << "0 0\n"; else out << c/d*x << ' ' << c/d*y << '\n';
    }
}