Cod sursa(job #2499414)
| Utilizator | Data | 26 noiembrie 2019 01:25:30 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <cstdio>
const int MOD = 1999999973;
int N, K;
int lgput(int base, int exponent) {
if (exponent == 0) {
return 1;
}
int subResult = lgput(base, exponent >> 1);
int subResultSquare = (1LL * subResult * subResult) % MOD;
if (exponent & 1) {
return (1LL * subResultSquare * base) % MOD;
}
return subResultSquare;
}
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;
}