Cod sursa(job #3161836)

Utilizator Chris_BlackBlaga Cristian Chris_Black Data 28 octombrie 2023 09:17:39
Problema Invers modular Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.58 kb
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int Mod = 1e9 + 7;

ll mul(ll a, ll b, int mod = Mod)
{
    return (a * b) % mod;
}
ll power(ll base, ll exp, int mod = Mod)
{
    ll ret = 1;
    while(exp)
    {
        if(exp & 1)
            ret = mul(ret, base, mod);
        base = mul(base, base, mod);
        exp >>= 1;
    }
    return ret;
}

int main()
{
    freopen("inversmodular.in", "r", stdin);
    freopen("inversmodular.out", "w", stdout);

    ll a, n;
    cin >> a >> n;
    cout << power(a, n - 2, n);
    return 0;
}