Help in Bit Manipulation problem

Can anyone please help me in solving this problem in O(1)? The constraints are pretty low and allows a bruteforce, but I was wondering how to do this, if L,R<= 10^{18}
Link - Problem
@carre @galencolin @ssrivastava990 @aneee004

did you check the discussion section of the problem?

There is a nice and fast solution