Cod sursa(job #1378201)
| Utilizator | Data | 6 martie 2015 10:59:01 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
#include <iostream>
using namespace std;
ifstream is("lgput.in");
ofstream os("lgput.out");
const int MOD = 1999999973;
int Pow( int a, int b );
int n, p;
int main()
{
is >> n >> p;
os << Pow(n, p);
is.close();
os.close();
return 0;
}
int Pow( int a, int b )
{
if ( b == 1 )
return a;
if ( b == 0 )
return 1;
int aux = Pow( a, b / 2 );
aux = ( 1LL * aux * aux ) % MOD;
if ( b & 1 )
aux *= a;
aux %= MOD;
return aux;
}
