Cod sursa(job #2689575)
Utilizator | Data | 21 decembrie 2020 13:53:42 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <fstream>
long long Exp(unsigned n, unsigned p)
{
if(p == 1)
return n;
long long Rez = Exp(n, p / 2);
Rez = Rez * Rez;
if(p % 2 != 0)
Rez = Rez * n;
return Rez % 1999999973;
}
int main()
{
std::ifstream f("in.in");
std::ofstream g("out.out");
unsigned N, P;
f >> N >> P;
g << Exp(N, P);
return 0;
}