Cod sursa(job #161742)
Utilizator | Popovici Adrian mithy | Data | 18 martie 2008 19:11:32 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 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)%1999999973, (n-1)/2))%1999999973);
else
return (pow((x*x)%1999999973, 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 ) % 1999999973);
return 0;
}