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 Digit DP - Codeforces. You should be able to solve it after this. If you want implementation help, you can go through CodeChef: Practical coding for everyone.

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.