Cod sursa(job #156490)
| Utilizator | Data | 12 martie 2008 16:31:31 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.42 kb |
#include <stdio.h>
#define modulo 1999999973
int n, p;
int pow(int x, int y)
{
int aux;
if (y == 0)
return 1;
if (y & 1)
return ((x * pow(x, y-1)) % modulo);
else
aux = (pow(x, y/2) % modulo);
return ((aux*aux) % modulo);
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out","w",stdout);
scanf("%d %d ", &n, &p);
printf("%d\n", pow(n, p));
return 0;
}
