Cod sursa(job #971225)

Utilizator superman_01Avramescu Cristian superman_01 Data 8 iulie 2013 19:44:12
Problema Invers modular Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include<fstream>
#include<algorithm>

#define LL long long

using namespace std;

ifstream f("inversmodular.in");
ofstream g("inversmodular.out");

int A,MOD;

LL lgput( int N , int P )
{
	int Sol=1;
	while( P )
	{
		if( P&1 )
			Sol=(Sol*N)%MOD;
		N=(N*N)%MOD;
		P>>=1;
	}
	return Sol;
}


LL inverse ( int N , int P )
{
	return lgput(N,P);
}
int main ( void )
{
	f>>A>>MOD;
	g<<inverse(A,MOD-2);
	f.close();
	g.close();
	return 0;
}