Problem:
Score : 900 points

Problem Statement

Nukes has an integer that can be represented as the bitwise OR of one or more integers between A and B (inclusive).
How many possible candidates of the value of Nukes's integer there are?

Constraints

1 ≤ A ≤ B < 2^{60}

A and B are integers.

Input

The input is given from Standard Input in the following format:

A
B

Output

Print the number of possible candidates of the value of Nukes's integer.

Sample Input 1

7
9

Sample Output 1

4

In this case, A=7 and B=9. There are four integers that can be represented as the bitwise OR of a non-empty subset of {7, 8, 9}: 7, 8, 9 and 15.

Sample Input 2

65
98

Sample Output 2

63

Sample Input 3

271828182845904523
314159265358979323

Sample Output 3

68833183630578410

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>

using namespace std;
int main(){
	long long a,b;
	cin >> a >> b;
	if(a==b){
		cout << 1 << endl;
		return 0;
	}
	long long a1 = a;
	long long b1 = b;
	bool v1[100]={},v2[100]={};
	for(int i=0;i<100;i++){
		if(a1%2==1){
			v1[i]=1;
		}
		if(b1%2==1){
			v2[i]=1;
		}
		a1 = a1/2;
		b1 = b1/2;
	}
	int ma=0;
	for(int i=0;i<100;i++){
		if(v1[i]!=v2[i]){
			ma = max(ma,i);
		}
	}
	long long k=((long long)1<<ma);
	a = a%k;
	b = b%k;
	long long ans=0;
	ans += k-a;
	int bm=0;
	for(int i=0;i<ma;i++){
		if(v2[i]==1){
			bm = max(bm,i);
		}
	}
	b = ((long long)1<<(bm+1))-1;
	if(a<=b){
		ans += k;
	}else{
		ans += b+1+k-a;
	}
	cout << ans << endl;
	return 0;
}