Cod sursa(job #150804)
| Utilizator | Data | 7 martie 2008 14:04:48 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.41 kb |
#include <stdio.h>
#define MOD 1999999973
long N, P;
long putere(long P)
{
if (P == 0)
return 1;
if (P == 1)
return N % MOD;
long x = putere(P>>1);
x = x * x % MOD;
if (P % 2) x = x * N % MOD;
return x;
}
int main()
{
freopen("lgput.in", "r", stdin);
freopen("lgput.out", "w", stdout);
scanf("%ld%ld", &N, &P);
printf("%ld\n", putere(P));
return 0;
}
