MAX = 200000 pre = [0] * MAX for i in range(MAX): pre[i] = (i % 2) + pre[i // 2] out = [] n = int(input()) for i in range(1, MAX): if n > 0: out.append(i) n -= pre[i] oo = [] while out: if pre[out[-1]] + n <= 0: n += pre[out[-1]] else: oo.append(out[-1]) out.pop() assert n == 0 print(len(oo)) print(' '.join(map(str, oo)))
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 28 | MAX = 200000 pre = [0] * MAX for i in range(MAX): pre[i] = (i % 2) + pre[i // 2] out = [] n = int(input()) for i in range(1, MAX): if n > 0: out.append(i) n -= pre[i] oo = [] while out: if pre[out[-1]] + n <= 0: n += pre[out[-1]] else: oo.append(out[-1]) out.pop() assert n == 0 print(len(oo)) print(' '.join(map(str, oo))) |