說穿了就是二分搜尋法

 

將 1~n 分成 1~n/2  0  1~n/2   (取 下高斯)

 

如此繼續......

 

#include<iostream>
#include<cmath>

 

 

using namespace std;

int main()
{
    unsigned long long int t, n;

    ios::sync_with_stdio(false);
    cin.tie(0);

    while(cin >> n)
    {
        t = log2(n+1);

        if(pow(2.0, t) != n+1)
            t++;

        cout << t << endl;
    }
}

arrow
arrow
    全站熱搜

    大神(偽) 發表在 痞客邦 留言(0) 人氣()