Cod sursa(job #2829340)
| Utilizator | Data | 8 ianuarie 2022 15:22:56 | |
|---|---|---|---|
| Problema | Invers modular | Scor | 60 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int n;
long long lg_pow(int x, int putere)
{
if(putere==1)
{
return x;
}
if(putere%2==0)
{
long long p=lg_pow(x,putere/2);
return p%n*p%n;
}
else
{
long long p=lg_pow(x,putere/2);
return x*p%n*p%n;
}
}
int main()
{
int a;
fin>>a>>n;
fout<<lg_pow(a,n-2)%n;
return 0;
}
