Cod sursa(job #1311975)
Utilizator | Data | 8 ianuarie 2015 19:37:14 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.59 kb |
#include <iostream>
#include <cstdio>
using namespace std;
void calc( int n , int p ) ;
int main()
{
int n , p ;
freopen( "lgput.in" , "r" , stdin ) ;
freopen( "lgput.out" , "w" , stdout ) ;
scanf( "%d %d" , &n , &p ) ;
calc( n , p ) ;
return 0;
}
void calc( int n , int p )
{
int sum = 1 ;
while ( p > 1 )
{
if ( p % 2 == 1 )
{
p -- ;
sum *= n ;
sum %= 1999999973 ;
}
n = n * n % 1999999973 ;
p /= 2 ;
}
printf( "%d" , (n * sum) %1999999973 ) ;
}