Cod sursa(job #661734)
| Utilizator | Data | 15 ianuarie 2012 00:11:51 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.53 kb |
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
using namespace std;
int N, P, CONST = 1999999973;
int exponentiation(int x, int p)
{
if (p == 0)
return 1;
else
if (p % 2)
return x * (int)pow(exponentiation(x, (p - 1) / 2), 2);
else
return (int)pow(exponentiation(x, p / 2), 2);
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%d %d", &N, &P);
printf("%d", exponentiation(N, P) % CONST);
}
