D题解 | #数树#
简单一点的代码,每一层节点数量为n,则这一层增加的完全二叉树的数量是sum = n+n/2+n/2/2+...n/2.../2。
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <queue>
#include <iostream>
using namespace std;
void my_ans(){
long long n,k,t=1,ans=0,mod = 1000000007;
cin>>n;
while(n>0){
k=min(t,n);
while(k>0){
ans = (ans+k)%mod;k=k/2;
}
n-=t;t=t*2;
}
cout<<ans<<endl;
return;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long t=1;
//scanf("%d",&t);
cin>>t;
while(t>0){
--t;my_ans();
}
return 0;
}
// 64 位输出请用 printf("%lld")