UPC Segment Tree 找规律 二进制

问题 G: Segment Tree

时间限制: 1 Sec  内存限制: 512 MB
提交: 74  解决: 17
[提交] [状态] [命题人:admin]

题目描述

Mcginn opens the code which he wrote 25 years ago.

Clever Mcginn wants to know how many positive interger n satisfied that the maximum c can reach whencall function build(1 , 1 , n) in the main function is m.
There are T test cases. Each case contains one integer m.

 

输入

Input is given from Standard Input in the following format:
T
m1
m2
.
.
.
mT
Constraints
1 ≤ T ≤ 100
1 ≤ m ≤ 1018

 

输出

For each m print one line denotes the answer.

 

样例输入

复制样例数据

3
3
4
5

样例输出

1
0
1

 

[提交][状态]

二进制打表找规律

代码:

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;

ll f[100];

int main() {
    int t;
    f[0] = 1;
    for (int i = 1; i <= 64; i++)
        f[i] = f[i - 1] * 2;
    cin >> t;
    while (t--) {
        ll n;
        cin >> n;
        if (n % 2 == 0) {
            cout << "0" << endl;
            continue;
        }
        if (n == 1) {
            cout << "1" << endl;
            continue;
        }
        int flag = -1, cnt = 0, v = 0;
        for (ll i = 63; i >= 0; i--) {
            if (n & f[i]) {
                cnt++;
                if (flag == -1) flag = 1;
                else if (flag == 0) flag = 2, v++;
                else if (flag==2) v++;
            } else {
                if (flag == 1) flag = 0;
            }
        }
        if (flag == 1) cout << "1" << endl;
        else {
            if (v == 1) cout << f[cnt - 2] << endl;
            else cout << "0" << endl;
        }
    }
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值