链接: 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;
- }
来源: http://www.bubuko.com/infodetail-2945438.html