Simple Enough problem

How can I approach this problem using divide and conquer?
I have made a tree-based solution but since the range is very high it will not work.

Your approach is perfectly fine but since the recursion is taking exponential time, you can use an alternate approach using the bitwise notation of the number and some properties of bitwise. Think about it for some time and I’ll tell you the approach.

Here’s my code, please don’t look at it before thinking first. It’ll spoil the fun problem.