Cod sursa(job #1452603)
| Utilizator | Data | 21 iunie 2015 13:51:24 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.44 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;
long long aux = pow(n, p / 2) % m;
if (p % 2 == 0) return aux * aux;
else return aux * n * aux;
}
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);
}