Cod sursa(job #3356497)
| Utilizator | Data | 1 iunie 2026 20:24:17 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int logexp(int a, int p){
if(p == 0){
return 1;
}
if(p % 2 == 0){
return logexp(a * a, p / 2);
}
else{
return a * logexp(a * a, p / 2);
}
return 1;
}
int main(){
int a, n;
fin >> a >> n;
fout << logexp(a, n - 2) % n;
fin.close();
fout.close();
return 0;
}