```
vector<int> countBits(int num) {
vector<int> result;
result.push_back(0);
int itr=0;
while(itr<num){
int size=result.size();
for(int i=0;i<size;++i){
if(itr<num){
++itr;
result.push_back(result[i]+1);
}
else
return result;
}
}
return result;
}
```