这题找规律即可。
1,3,4,9,10,11,13,27,28,30,31,36,37,39,40,81…
上标:
#include<cstdio>
#define ll long long
using namespace std;
int T,n;
ll ans,s,plus,now;
inline int read()
{
int x=0; char c=getchar();
while (c<'0' || c>'9') c=getchar();
while (c>='0' && c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x;
}
int main()
{
freopen("recruitment.in","r",stdin);
freopen("recruitment.out","w",stdout);
T=read();
while (T--)
{
n=read();
ans=now=0;
while (now<n)
{
plus=s=1;now++;
while (now+plus<=n)
s*=3,now+=plus,plus<<=1;
ans+=s;
}
printf("%lld
",ans);
}
return 0;
}