Cod sursa(job #3366820)
| Utilizator | Data | 4 octombrie 2026 15:08:17 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.43 kb |
#include <fstream>
#define MOD 1999999973
std::ifstream fin("lgput.in");
std::ofstream fout("lgput.out");
int n, p;
int logExpo(int n, int p) {
int answer = 1;
while (p > 0) {
if (p % 2 == 1) {
answer = 1LL * answer * n % MOD;
}
n = 1LL * n * n % MOD;
p /= 2;
}
return answer;
}
int main() {
fin >> n >> p;
fout << logExpo(n, p) << "\n";
}