题意不说了。
思路:
先要快速接近目标n 所以 不断取2 4 8 16 32... 直到恰好小于n为止,这时在加1就可以了
STL 中的lower_bound 恰好实现这个功能!
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int a[35];
void init(){
a[0] = 1;
for (int i = 1; i < 32; ++i){
a[i] = a[i-1] * 2;
}
}
int main(){
init();
int n,cnt=0;
while(scanf("%d",&n) == 1 && n > 0){
int m = lower_bound(a,a+31,n)-a;
printf("Case %d: %d\n",++cnt,m);
}
return 0;
}