Cod sursa(job #682499)

Utilizator michael9ufoStanescu Mihai michael9ufo Data 19 februarie 2012 01:41:49
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.66 kb
#include <cstdio>

using namespace std;

long long lpow(long long b, long long e)
{
	long long rez = 1;

/*
	if(e == 0)
		rez = 1;
	else
	{
		
		if(e % 2 == 0)
			rez = lpow(b * b % 1999999973, e / 2) % 1999999973;
		else
			rez = lpow(b * b % 1999999973, e / 2) * b % 1999999973;
	
	}*/
	
	while(e)
	{
	
		if(e % 1)
			rez = (rez * b) % 1999999973;
			
		e >>= 1;
		
		b = (b * b) % 1999999973;

	}

	return rez;

}

int main()
{

	FILE *in, *out;
	
	in = fopen("lgput.in", "r");

	out = fopen("lgput.out", "w");
	
	long long N, P;
	
	fscanf(in, "%lld %lld", &N, &P);

	fprintf(out, "%lld", lpow(N, P));

	return 0;

}