Pagini recente » Cod sursa (job #1955122) | Cod sursa (job #1069793) | tema | Cod sursa (job #2770203) | Cod sursa (job #580454)
Cod sursa(job #580454)
#include <fstream>
using namespace std;
const char InFile[]="inversmodular.in";
const char OutFile[]="inversmodular.out";
ifstream fin(InFile);
ofstream fout(OutFile);
int A,N;
inline int mypow(int A, int B)
{
int sol=1;
A%=N;
for(;B;B>>=1)
{
if((B&1)==1)
{
sol=(1LL*sol*A)%N;
}
A=(1LL*A*A)%N;
}
return sol;
}
int main()
{
fin>>A>>N;
fin.close();
fout<<mypow(A,N-2);
fout.close();
return 0;
}