Cod sursa(job #2924453)
| Utilizator | Data | 2 octombrie 2022 19:34:40 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
#define PRIME 1999999973
typedef unsigned long long u64;
u64 pow(u64 base, u64 exponent) {
u64 ans = 1;
while (exponent > 0) {
if (exponent & 1) ans = (ans % PRIME * base % PRIME) % PRIME;
exponent >>= 1;
base = (base % PRIME * base % PRIME) % PRIME;
}
return ans;
}
int main() {
std::ifstream input("lgput.in");
std::ofstream output("lgput.out");
u64 n, p;
input >> n >> p;
output << pow(n, p);
return 0;
}
