- 数列
- 2017-01-19 13:56:53 @
用递归强过,代码贴出:
#include<stdio.h>
int log2x(int N)
{
int ret = 0;
int t = N;
while ( t > 1 ) {
t /= 2;
ret ++;
}
return ret;
}
int power(int a,int b){
int t=1;
for (int i=0;i<b;i++){
t*=a;
}
return t;
}
int fun(int k,int N){
if (power(2,log2x(N))==N) return power(k,log2x(N));
else return fun(k,power(2,log2x(N)))+fun(k,N-power(2,log2x(N)));
}
int main(){
int k,N;
scanf("%d %d",&k,&N);
printf("%d",fun(k,N));
return 0;
}
0 条评论
目前还没有评论...