1. 程式人生 > >牛客寒假6-G.區間或和

牛客寒假6-G.區間或和

return 。。 space cin 二進制位 light urn mes code

鏈接:https://ac.nowcoder.com/acm/contest/332/G

題意:

求a|(a+1)|(a+2)|...|(b-1)|b。

思路:

求a-b的差的每一個二進制位

自己也看不懂。。。

代碼:

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;


int main()
{
    LL a,b;
    while(cin >> a >> b)
    {
        LL res = a;
        LL x = 1;
        while (a + x <= b)
        {
            res |= (x + a);
            x <<= 1;
        }
        cout << (res|b) << endl;
    }

    return 0;
}

  

牛客寒假6-G.區間或和