Cod sursa(job #820443)
Utilizator | Daniel Amariei daniel.amariei | Data | 20 noiembrie 2012 20:44:03 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | c | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include <stdio.h>
#define M 1999999973
int main(void)
{
int N, P;
long long int res = 1;
long long int n = 0;
freopen("lgput.in", "r", stdin) ;
freopen("lgput.out", "w", stdout) ;
scanf("%d %d", &N, &P);
n = N;
while (P != 0)
{
if ((P & 1) != 0) // numarul este impar ?
res = (res * n) % M;
n = (n * n) % M;
P >>= 1;
}
printf("%lld\n", res);
return 0;
}