#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;

class KleofasTail { public:
	long long countGoodSequences(long long K, long long A, long long B)
	{
		return solve(K,B) - solve(K,A-1);
	}
	LL solve(LL K, LL U)
	{
		if(U==-1)
			return 0;
		if(K==0)
			return U+1;

		LL v = 0;
		for(int i=0; (K<<i)<=U; ++i) {
			if( (K+1<<i)-1 <= U )
				v += (1LL<<i);
			else
				v += U - (K<<i) + 1;
		}
		if((K&1)==0) {
			++K;
			for(int i=0; (K<<i)<=U; ++i) {
				if( (K+1<<i)-1 <= U )
					v += (1LL<<i);
				else
					v += U - (K<<i) + 1;
			}
		}
		return v;
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const long long& Expected, const long long& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, KleofasTail().countGoodSequences(K, A, B));}
int main(){
CASE(0)
	long long K = 3LL; 
	long long A = 4LL; 
	long long B = 8LL; 
	long long _ = 2LL; 
END
CASE(1)
	long long K = 1LL; 
	long long A = 23457LL; 
	long long B = 123456LL; 
	long long _ = 100000LL; 
END
CASE(2)
	long long K = 1234567890123456LL; 
	long long A = 10LL; 
	long long B = 1000000LL; 
	long long _ = 0LL; 
END
CASE(3)
	long long K = 0LL; 
	long long A = 0LL; 
	long long B = 2LL; 
	long long _ = 3LL; 
END
CASE(4)
	long long K = 2LL; 
	long long A = 3LL; 
	long long B = 3LL; 
	long long _ = 1LL; 
END
CASE(5)
	long long K = 13LL; 
	long long A = 12345LL; 
	long long B = 67890123LL; 
	long long _ = 8387584LL; 
END
CASE(6)
	long long K = 2LL; 
	long long A = 0LL; 
	long long B = 6LL; 
	long long _ = 5LL; 
END
CASE(7)
	long long K = 2LL; 
	long long A = 0LL; 
	long long B = 9999999999999LL; 
	long long _ = -1LL; 
END

}
// END CUT HERE
