Cod sursa(job #2725386)
Utilizator | Data | 18 martie 2021 21:05:48 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin ("lgput.in");
ofstream fout ("lgput.out");
int exp(int a, int n, int mod) {
if(n == 0)
return 1;
if(n % 2 == 0) {
int x = exp(a, n/2, mod);
return 1ll * x * x % mod;
}
return 1ll * a * exp(a, n-1, mod) % mod;
}
int main() {
int a, n; fin >> a >> n;
fout << exp(a, n-2, n);
}