```
class Solution(object):
def countBits(self, num):
res, exp = [], 4
for i in xrange(num+1):
if i == 0 or i == 1:
res.append(i)
else:
exp = exp if i < exp else exp << 1
res.append(res[i-exp/2] + 1)
return res
```