Cod sursa(job #1452598)
| Utilizator | Data | 21 iunie 2015 13:46:48 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <stdio.h>
#include <string.h>
const int m = 1999999973;
long long pow(unsigned int n, unsigned int p) {
if (p == 0) return 1;
else if (p % 2 == 0) return pow(n, p / 2) * pow (n, p / 2);
else return pow(n, p / 2) * n * pow(n, p / 2);
}
int main() {
unsigned int n, p;
long long rez;
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d %d", &n, &p);
rez = pow(n, p);
printf("%lld", rez % m);
}