HPU's birthday

题目描述
2019.10.20 is the 110th birthday of HPU. On that day, you can see the string “110” everywhere.
Hery is given an integer n in decimal, he can transform n to a binary string S. For example: (6)_{10}=(110)_2(6)
10 =(110) 2

, so 6 can be transformed to “110”. But hery thinks S is too short, so he constructs n’s birthday string T by repeating n’s binary string S for n times. So for n=6, n’s birthday string T is:

“110110110110110110”

For n’s birthday string T, hery wants you to calculate how many pairs (i,j,k) satisfy 1 \leq i < j < k \leq |T|1≤i<j<k≤∣T∣

输入描述:
The first line is an integer t, the number of test cases.
Next t lines, for each line, there is an integer n.
(1 \leq t \leq 10,1 \leq n \leq 10^5)(1≤t≤10,1≤n≤10
5
)
输出描述:
For each n, output the answer mod 10^9+710
9
+7.
示例1
输入
复制
4
1
2
3
11
输出
复制
0
1
0
1815
思路:就是先把它转换成二进制,然后从后往前找零,以及零前面的1的个数,然后就是零前面的1
中挑两个组成110。

#include<bits/stdc++.h>
using namespace std;
const int N=1e9+7;
int main(){
    long long T;
    cin>>T;
    while(T--){
        long long temp,a=0,b=0,sum=0,f[50],idx=0;
        cin>>temp;
        sum=temp;
        while(temp){
            f[idx++]=temp%2;
            temp/=2;
        }
        for(int j=0;j<sum;j++){
            for(int i=idx-1;i>=0;i--){
                if(f[i]==1)
                    a=(a+1)%N;
                if(f[i]==0)
                    b=(b+(a-1)*a/2)%N;
            }
        }
        cout<<b<<endl;
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值