Cod sursa(job #2915646)

Utilizator UnknownPercentageBuca Mihnea-Vicentiu UnknownPercentage Data 23 iulie 2022 19:46:57
Problema Algoritmul lui Euclid extins Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.34 kb
#include <bits/stdc++.h>

#define vt vector
#define pb push_back
#define em emplace
#define emb emplace_back

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

void re() {
}

void wr() {
}

template <typename fir, typename ...sec> void re(fir &x, sec&... y) {
    cin >> x;
    re(y...);
}

template <typename fir, typename ...sec> void wr(fir x, sec... y) {
    cout << x;
    wr(y...);
}

inline void Open(const string Name) {
    #ifndef ONLINE_JUDGE
        (void)!freopen((Name + ".in").c_str(), "r", stdin);
        (void)!freopen((Name + ".out").c_str(), "w", stdout);
    #endif
}

void solve() {
    int a, b, c; re(a, b, c);
    auto egcd = [&](auto&& egcd, int a, int b, int& x, int& y) -> int {
        if(b == 0) {
            x = 1, y = 0;
            return a;
        }
        int x1, y1;
        int d = egcd(egcd, b, a % b, x1, y1);
        x = y1;
        y = x1 - y1 * (a / b);
        return d;
    };

    int x, y;
    int z = egcd(egcd, a, b, x, y);
    if(c % z) {
        wr("0 0\n");
        return;
    }

    wr(x * (c / z), ' ', y * (c / z), '\n');
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    Open("euclid3");

    int t; re(t);
    for(;t;t--) {
        solve();
    }

    return 0;
}