Cod sursa(job #580454)

Utilizator ChallengeMurtaza Alexandru Challenge Data 13 aprilie 2011 08:47:05
Problema Invers modular Scor 60
Compilator cpp Status done
Runda Arhiva educationala Marime 0.45 kb
#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;
}