Cod sursa(job #2120497)

Utilizator SenibelanMales Sebastian Senibelan Data 2 februarie 2018 15:32:28
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.44 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;
        p /= 2;
    }
    out << sol << "\n";
}

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

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