Cod sursa(job #2414056)

Utilizator rares9991Matisan Rares-Stefan rares9991 Data 24 aprilie 2019 00:11:26
Problema Invers modular Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.39 kb
#include <fstream>

using namespace std;
long long mod,a,n;

long long putere(int a,int p)
{
    if(p==0)
        return 1;
    long long x=putere(a,p>>1);
    if(p%2==0)
        return (x*x)%n;
    else
        return (((x*x)%n)*a)%n;
}

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

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