Cod sursa(job #481381)

Utilizator SzabiVajda Szabolcs Szabi Data 31 august 2010 15:27:00
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.42 kb
#include <stdio.h>
#define MAR 1999999973
int n,p;


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

	return (temp*temp)%MAR;

	}else{
	int 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("%d %d",&n,&p);

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


	return 0;}