Cod sursa(job #1168786)
Utilizator | Data | 9 aprilie 2014 16:24:33 | |
---|---|---|---|
Problema | Invers modular | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.42 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("inversmodular.in");
ofstream fout("inversmodular.out");
int Pow(int a, int n)
{
int p=1, MOD=n+2 ;
while (n>0)
{
if (n%2==1)
{
p=1LL*a*p%MOD;
n--;
}
a=a*a%MOD;
n/=2;
}
return p%MOD ;
}
int main()
{
int a,n;
fin>>a>>n;
fout<<Pow(a,n-2)<<'\n';
fin.close();
fout.close();
return 0;
}