Cod sursa(job #157478)

Utilizator mithyPopovici Adrian mithy Data 13 martie 2008 01:04:18
Problema Ridicare la putere in timp logaritmic Scor 10
Compilator cpp Status done
Runda Arhiva educationala Marime 0.38 kb
#include <stdio.h>

typedef unsigned long ulong;

ulong pow( ulong x, ulong n )
{
	if ( n == 0 )
		return 1;

	if ( n % 2 )
		return x * pow(x*x,(n-1)/2);
	else
		return pow(x*x, n/2);
}

int main()
{
	ulong x, n;

	freopen( "lgput.in", "rt", stdin );
	freopen( "lgput.out", "wt", stdout );

	scanf( "%ld %ld", &x, &n );
	printf( "%ld\n", pow( x, n ) );

	return 0;
}