Cod sursa(job #2917242)

Utilizator UnknownPercentageBuca Mihnea-Vicentiu UnknownPercentage Data 3 august 2022 22:22:36
Problema Invers modular Scor 100
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 1.42 kb
#include <bits/stdc++.h>

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

#define all(x) x.begin() + 1, x.end()

using namespace std;

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

using pii = pair <int, int>;
using pll = pair <ll, ll>;

void re() {
}

void wr() {
}

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

template <typename pfir, typename psec, typename ...sec> void re(pair <pfir, psec> &x, sec&... y) {
    re(x.first, x.second);
    re(y...);
}

template <typename fir, typename ...sec> void re(vt <fir>& x, sec&... y) {
    for(int i = 1;i < x.size();i++)
        re(x[i]);
    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() {
    ll a, b; re(a, b);
    auto inv = [](auto&& inv, ll a, ll b) -> ll {
        return (1 < a)? b - inv(inv, b % a, a) * b / a : 1;
    };
    wr(inv(inv, a, b));
}

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

    Open("inversmodular");

    int t = 1;
    for(;t;t--) {
        solve();
    }

    return 0;
}