Cod sursa(job #1384630)
| Utilizator | Data | 11 martie 2015 11:38:14 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
#define LL long long
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
LL A, N;
LL PPP(LL n, LL p)
{
if (p == 0) return 1;
if (p == 1) return n;
if (p % 2 == 0) return (PPP((n * n) % N, p / 2)) % N;
return (n * PPP(n * n, p / 2)) % N;
}
int main()
{
LL p;
fin >> A >> N;
p = N - 2;
fout << PPP(A, p) % N;
return 0;
}
