Cod sursa(job #2863389)
| Utilizator | Data | 6 martie 2022 17:22:52 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int log_pow(int x, int p, int mod)
{
int rez = 1;
while(p)
{
if(p % 2 == 1)
{
rez = (rez * x) % mod;
}
x = (x * x) % mod;
p /= 2;
}
return rez;
}
int main()
{
int x, n;
fin >> x >> n;
fout << log_pow(x, n - 2, n);
return 0;
}
