Cod sursa(job #2499415)
| Utilizator | Data | 26 noiembrie 2019 01:31:53 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <cstdio>
const int MOD = 1999999973;
int N, K;
int lgput(int base, int exponent) {
int result = 1, basePow2Value = base;
for (int powIdx = 0; (1 << powIdx) <= exponent; powIdx++) {
if (exponent & (1 << powIdx)) {
result = (1LL * result * basePow2Value) % MOD;
}
basePow2Value = (1LL * basePow2Value * basePow2Value) % MOD;
}
return result;
}
int main() {
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d%d", &N, &K);
printf("%d\n", lgput(N, K));
return 0;
}