Cod sursa(job #3304952)

Utilizator Gabriel_DaescuDaescu Gabriel Florin Gabriel_Daescu Data 28 iulie 2025 23:27:45
Problema Invers modular Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.44 kb
#include <fstream>
using namespace std;
ifstream  fin("inversmodular.in");
ofstream fout("inversmodular.out");
long long A,N;

long long fast_exp(long long b, long long e)
{
    long long ans=1;
    while(e)
    {
        if(e%2==1)
        {
            ans=(ans*b)%N;
        }
        b=(b*b)%N;
        e=e/2;
    }
    return ans;
}

int main()
{
    fin>>A>>N;

    fout<< fast_exp(A,N-2) << "\n";

    return 0;
}