Cod sursa(job #2499629)
Utilizator | Data | 26 noiembrie 2019 15:56:29 | |
---|---|---|---|
Problema | Invers modular | Scor | 60 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include<fstream>
#include<queue>
#define DIM 10010
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int a,mod;
int invmod(long long n)
{
long long sol=1,aux=mod-2;
while(aux>0)
{
if(aux%2==1) sol=(sol*n)%mod;
n=(n*n)%mod;
aux/=2;
}
return sol;
}
int main()
{
fin>>a>>mod;
fout<<invmod(a);
return 0;
}