Cod sursa(job #1098647)
Utilizator | Data | 4 februarie 2014 23:16:37 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.54 kb |
/* Ridicare la putere folosind exponentiere logaritmica */
#include <fstream>
using namespace std;
#define MOD 1999999973
long long N, P, R;
void Pow(long long P)
{
if (P == 0)
{
R = 1;
return;
}
else
{
Pow(P / 2);
if (P % 2)
{
R = (R * R * N) % MOD;
}
else
{
R = (R * R) % MOD;
}
}
}
int main()
{
ifstream f("lgput.in");
ofstream g("lgput.out");
f >> N >> P;
Pow(P);
g << R;
}