Cod sursa(job #2120498)

Utilizator SenibelanMales Sebastian Senibelan Data 2 februarie 2018 15:34:05
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <fstream>

using namespace std;

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

int A, N;

void Read(){
    in >> A >> N; 
}

void Power(int n, int p){
    int sol = 1;
    while(p){
        if(p % 2 == 1)
            sol = ((sol % N) * (n % N)) % N;
        n = ((n % N) * (n % N)) % N;
        p /= 2;
    }
    out << sol << "\n";
}

void SolveAndPrint(){
    Power(A, N - 2);
}

int main(){
    Read();
    SolveAndPrint();
    return 0;
}