Cod sursa(job #2029733)
| Utilizator | Data | 30 septembrie 2017 13:06:38 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <fstream>
using namespace std;
ifstream in("inversmodular.in");
ofstream out("inversmodular.out");
long long expow(long long b, long long e, long long mod) {
long long ans = 1;
while (e > 0) {
if (e % 2)
ans = ans * b % mod;
b = b * b % mod;
e/= 2;
}
return ans;
}
int main()
{
int a, n, p = 1;
in >> a >> n;
out << expow(a, n - 2, n);
return 0;
}
