```
vector<int> countBits(int num) {
vector<int> sums(num+1, 0);
if (num == 0)
{
return sums;
}
int i,j = 1;
for (i = 1; i <= num; i++)
{
if (!((i - 1) & i))
{
j = 1;
sums[i] = 1;
continue;
}
sums[i] = sums[j++] + 1;
}
return sums;
}
```