Playing with bits

Any hint how to find count of setbits from 1 to n ?

Yes for each number you can find the number of set bits in any number n in log(n) time using builtin_popcount(i) and total time would be n*log(n).