Cod sursa(job #481385)

Utilizator SzabiVajda Szabolcs Szabi Data 31 august 2010 15:35:20
Problema Ridicare la putere in timp logaritmic Scor 100
Compilator cpp Status done
Runda Arhiva educationala Marime 0.5 kb
#include <stdio.h>
#define MAR 1999999973

typedef long long  tipus;

tipus n,p;


tipus kit(tipus i, tipus k){
	if(k==0){return 1;}
	else if(k==1){return i%MAR;}
	else if(k%2==0){
	tipus temp;
	temp=kit(i,k/2);

	return (temp*temp)%MAR;

	}else{
	tipus temp;
	temp=kit(i,(k-1)/2);

	return (((temp*temp)%MAR)*i)%MAR;

	}
}


int main(){
	freopen("lgput.in","r",stdin);
	freopen("lgput.out","w",stdout);

	scanf("%lld %lld",&n,&p);

	printf("%lld",kit(n,p));


	return 0;}