2019.01.27【NOIP提高组】模拟B组 JZOJ 1273 袁绍的刁难
程序员文章站
2024-03-17 13:17:04
...
选第个武将的价值是,求第大的代价
进制转换题,不想多说。
#include<cstdio>
using namespace std;long long power[35],k,ans,j;
int n;
signed main()
{
freopen("recruitment.in","r",stdin);
freopen("recruitment.out","w",stdout);
power[0]=1;
for(register int i=1;i<33;i++) power[i]=power[~-i]+(power[~-i]<<1);//预处理3的任意次方
scanf("%d",&n);
while(n--)
{
scanf("%lld",&k);
j=0;ans=0;
while(k)
{
if(k&1) ans+=power[j];
k>>=1;j++;
}
printf("%lld\n",ans);
}
}