Cod sursa(job #664601)
Utilizator | Data | 20 ianuarie 2012 14:55:35 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.33 kb |
#include <cstdio>
int v[100000000];
int main(){
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
unsigned long long A,B=1,pow;
int i,j;
scanf("%lld %lld",&pow,&B);
A=1;
for(i=1;B!=0;i++){
v[i]=B%2;
B/=2;
}
i--;
for(j=i;j>0;--j){
A*=A;
if(v[j]==1){
A*=pow;
}
}
printf("%d",A);
}