Cod sursa(job #472545)
Utilizator | Data | 25 iulie 2010 15:53:08 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.31 kb |
#include <stdio.h>
#define C 1999999973
long long n,p;
int main(){
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
scanf("%lld %lld",&n,&p);
long long put =1;
for (int i = 0; (1<<i) <= p ; i++){
if(( (1<<i) & p ) > 0 )
put = (put*n)%C;
n=(n*n)%C;
}
printf("%lld",put);
return 0;
}