Cod sursa(job #628761)

Utilizator cristicecCristian Uricec cristicec Data 2 noiembrie 2011 01:35:02
Problema Ridicare la putere in timp logaritmic Scor 30
Compilator cpp Status done
Runda Arhiva educationala Marime 0.41 kb
#include<stdio.h>

using namespace std;
long long n,p;
long long fct(long long n,long long p){
	if(p==0) return 1;
	else
		if(p%2==0) return (fct(n,p/2)*fct(n,p/2))%1999999973;
		else return ((n%1999999973)*fct(n,(p-1)/2)*fct(n,(p-1)/2))%1999999973;
}

int main(){
	freopen("lgput.in","r",stdin);
	freopen("lgput.out","w",stdout);
	scanf("%lld%lld", &n, &p);
	printf("%lld", fct(n,p));
	return 0;
}