Cod sursa(job #2124387)

Utilizator alxcl12Albu Alexandru alxcl12 Data 7 februarie 2018 10:43:27
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include <iostream>
#include <fstream>

std::ifstream f("inversmodular.in");
std::ofstream g("inversmodular.out");

int n;

int my_pow(int a,int b)
{
    long long r=1;
    while(b)
    {
        if(b%2) {r=(a%n)*(r%n); r%=n;}
        a*=a;
        a%=n;
        b/=2;
    }
    return r;
}

using namespace std;

int main()
{
    int a;
    f>>a>>n;
    g<<my_pow(a,n-2);

    return 0;
}