题目链接:http://lightoj.com/volume_showproblem.php?problem=1032
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std; const int maxn = ;
const int INF = 0x3f3f3f; long long dp[maxn];
int sum[] = {,,,,,,,,};
long long int N; inline long long res(int i){
return (<<i) + (<<(i-));
} int main()
{
freopen("E:\\acm\\input.txt","r",stdin);
dp[] = ;
for(int i=;i<=;i++){
dp[i] = *dp[i-] + (<<(i-));
}
int T;
cin>>T;
for(int cas=;cas<=T;cas++){
cin>>N;
printf("Case %d: ",cas);
if(N <= ){
printf("%d\n",sum[N]);
continue;
}
long long ans = ;
for(int i=;i>=;i--){
long long temp = <<i;
if(N >= temp){
ans += dp[i];
long long diff = N - res(i);
if(diff >= ){ //这个地方没有加等号WA了两次。
ans += diff + ;
}
N -= temp;
}
if(N == ) break;
}
cout<<ans+sum[N]<<endl;
}
}