Troublesome Vijay Help

Problem: https://www.codechef.com/problems/COWA19A/
This is my solution for Troublesome Vijay : https://www.codechef.com/viewsolution/29032075

Basically, I calculated how many numbers between 1 and N have their ith bit ‘1’ for all i (max 32). Then I added their contribution. I’ve checked it alongside the Brute-force method for N upto 1e6 and it works.
Maybe it’s something about overflowing at bigger values or corner cases that I’m unable to find.
Any help would be appreciated.