题目链接:点击这里
思路:统计
的个数,则统计以每一个
结束时,看他前面能组成多少个
(即
)
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const int maxn = 1010;
int t, tmp, n;
int a[maxn];
int main()
{
scanf("%d", &t);
while(t--)
{
memset(a, 0, sizeof(a));
scanf("%d", &n);
tmp = n;
int cnt = 0;
while(tmp)
{
a[++cnt] = tmp % 2;
tmp /= 2;
}
ll num = 0;
ll ans = 0;
for(int i = 1; i <= n; i++)
{
for(int j = cnt; j >= 1; j--)
{
if(a[j]) num++;
else ans = (ans + num*(num-1)/2) % MOD;
}
}
printf("%lld\n", ans);
}
return 0;
}