Cod sursa(job #146716)
Utilizator | Victor-Nicolae Savu Viksen | Data | 2 martie 2008 00:40:37 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <stdio.h>
int n,p,prd=1;
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;
}