Cod sursa(job #2900847)

Utilizator RaresPoinaruPoinaru-Rares-Aurel RaresPoinaru Data 12 mai 2022 11:14:20
Problema Invers modular Scor 0
Compilator cpp-64 Status done
Runda Arhiva educationala Marime 0.49 kb
#include <bits/stdc++.h>
using namespace std;

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

long long a,n;

int Putere(int A , int e)
{
    if (e==0)
        return 1;
    if (e==1)
        return A;
    int P = 1;
    while(e)
    {
        if(e % 2 == 1)
            P = P * A % n;
        A = A * A % n;
        e /= 2;
    }
    return P;
}

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