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