Cod sursa(job #157479)
Utilizator | Popovici Adrian mithy | Data | 13 martie 2008 01:05:04 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 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))%1999999973);
else
return (pow(x*x, n/2)%1999999973);
}
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;
}