Cod sursa(job #146715)
Utilizator | Victor-Nicolae Savu Viksen | Data | 2 martie 2008 00:38:36 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <stdio.h>
int n,p,prd;
int main ()
{
freopen ( "lgput.in" , "r" , stdin );
scanf ( "%d %d" , &n , &p );
fclose ( stdin );
do
{
if (p&1) prd = ((long long) prd * n ) % 1999999973;
n= ((long long) n * n ) % 1999999973;
} while (p>>=1);
freopen ( "lgput.out" , "w" , stdout );
printf ( "%d\n" , prd );
fclose ( stdout );
return 0;
}