#!python
n = int(input())
bits = [0]
pref = [0]
s = 0
i = 1
while n > s:
b = bin(i).count("1")
s += b
bits.append(b)
pref.append(s)
i += 1
i -= 1
res = []
while n > 0:
if n <= pref[i-1]:
i -= 1
continue
res.append(i)
n -= bits[i]
i -= 1
print(len(res))
print(' '.join([str(r) for r in res]))
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #!python n = int(input()) bits = [0] pref = [0] s = 0 i = 1 while n > s: b = bin(i).count("1") s += b bits.append(b) pref.append(s) i += 1 i -= 1 res = [] while n > 0: if n <= pref[i-1]: i -= 1 continue res.append(i) n -= bits[i] i -= 1 print(len(res)) print(' '.join([str(r) for r in res])) |
English