import math

class Solution(object):

def countBits(self, num):

"""

:type num: int

:rtype: List[int]

"""

if num == 0:

return [0]

```
m = math.ceil(math.log(num) / math.log(2))
i = 0
result = [0]
cur = [1]
result += cur
while(i <= m):
cur += [j + 1 for j in cur]
result += cur
i += 1
return result[0:num + 1]
```