Cod sursa(job #1268955)
Utilizator | Data | 21 noiembrie 2014 18:14:47 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.39 kb |
#include <fstream>
using namespace std;
ifstream in("lgput.in");
ofstream out("lgput.out");
long long f( long long b, long long e )
{
if ( e == 0 )
return 1;
if ( e % 2 == 1 )
return ( b*f(b, e - 1 ) ) % 1999999973;
if ( e % 2 == 0 )
return ( f(b,e/2)*f(b,e/2) ) % 1999999973;
}
int main()
{
int n, p;
in >> n >> p;
out << f(n,p);
return 0;
}