Cod sursa(job #2855238)

Utilizator andrei_laurentiuRadu Andrei-Laurentiu andrei_laurentiu Data 22 februarie 2022 11:20:03
Problema Invers modular Scor 60
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.54 kb
#include <iostream>
#include <fstream>

using namespace std;

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

long long putere(int a, int b, int n)
{
    long long aa = 1, ans = 1;

    while(b)
    {
        if(b & 1LL)// exp impar deci inmultim rezultatul cu baza
        {
            ans *= a;
            ans %= n;
        }
        a = 1LL * a * a % n;
        b >>= 1LL;
    }

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

    return 0;
}