Solved: - How to get the number of set bits at every position from number 1 to n in logn time complexity?


I need to know this for this problem. Please explain your approach.

1 Like

Anyone??

This is a classic digit DP problem. There a quite a few blogs on this topic. One of them is https://codeforces.com/blog/entry/53960. You should be able to solve it after this. If you want implementation help, you can go through https://www.codechef.com/viewsolution/29029188.

The problem you mention has an editorial with example code that answers exactly what you ask

But i am not able to understand the editorial.