Cod sursa(job #2800755)
| Utilizator | Data | 13 noiembrie 2021 21:40:47 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
int n;
int fastpow(long long a, int p){
long long x = 1;
while(p > 0){
if(p & 1)
x = (x * a) % n;
a = (a * a) % n;
p /= 2;
}
return x;
}
int invers_modular(int a){
int x;
x = fastpow(a, n - 2);
return x;
}
int main()
{
int a;
in >> a >> n;
out << invers_modular(a);
return 0;
}
