Cod sursa(job #2285306)
Utilizator | Ghita Alexandru Alexghita96 | Data | 18 noiembrie 2018 14:09:11 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp-64 | Status | done |
Runda | Arhiva educationala | Marime | 0.57 kb |
#include <cstdio>
#define MOD 1999999973
using namespace std;
int main() {
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
int n, p;
int result;
int times_two = 0;
scanf("%d %d", &n, &p);
result = n;
while (p > 1) {
if (p % 2) {
times_two++;
p--;
} else {
result = (result * result) % MOD;
p /= 2;
}
}
while (times_two) {
result = (result * n) % MOD;
times_two--;
}
printf("%d", result);
}