class Solution

{

public:

vector <int> countBits(int n)

{

vector<int> BitsNum(n + 1, 0);

BitsNum[0] = 0;

BitsNum[1] = 1;

if( n == 1) return BitsNum;

int i = 1;

int Nf = 2;

while( i <= n)

{

```
for( i = Nf; i < 2*Nf && i <= n; i++)
{
BitsNum[i] = BitsNum[i - Nf] + 1;
}
Nf += Nf;
}
return BitsNum;
}
```

};