Cod sursa(job #2740842)
| Utilizator | Data | 14 aprilie 2021 15:25:06 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
unsigned long long RidicareLogaritmica(unsigned long N, unsigned long P) {
if (N == 2)
return 1LL * 1 << P;
unsigned long long ret = 1;
while (P != 0) {
if ((P & 1) == 1)
ret = ret * N;
N = N * N;
P /= 2;
}
return ret;
}
int main() {
std::ifstream fin("lgput.in");
std::ofstream fout("lgput.out");
unsigned long N, P;
fin >> N >> P;
fout << RidicareLogaritmica(N, P) % 1999999973 << '\n';
return 0;
}