Cod sursa(job #688900)

Utilizator antonioteoZait Teodor Antonio antonioteo Data 23 februarie 2012 22:29:03
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.4 kb
#include <cstdio>
#define M 1999999973
#define LL long long
using namespace std;
int a, b;
int lgput(LL a , LL b){
	LL p = 1;
	while ( b > 1 ){
		if ( b % 2 == 1 ) p = ( p * a ) % M;
		a = ( a * a ) % M;
		b = b / 2;
	}
	return ( a * p ) % M;
}
int main(){
	freopen("lgput.in","r",stdin); freopen("lgput.out","w",stdout);
	scanf("%d%d", &a, &b); 
	printf("%lld\n", lgput(a,b));
	return 0;
}