Cod sursa(job #2863381)

Utilizator Andrei_Tud1Andrei Tudorache Andrei_Tud1 Data 6 martie 2022 17:17:45
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.47 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");

int log_pow(int x, int p, int mod)
{
    int rez = 1;
    while(p != 0)
    {
        if(p % 2 == 1)
        {
            rez = rez * x % mod;
        }

        x = x * x % mod;
        p /= 2;
    }
    return rez;
}

int main()
{
    int x, n;
    fin >> x >> n;
    fout << log_pow(x, n - 2, n);
    return 0;
}