n = int(input()) i = 0 c = 0 bins = {} while c < n: i += 1 b = bin(i).count('1') c += b bins[i] = b x = c - n if x == 0: print(len(bins)) print(*reversed(bins)) else: delete = [] for i, b in reversed(bins.items()): if b <= x: x -= b delete.append(i) if x == 0: break for key in delete: del bins[key] print(len(bins)) print(*reversed(bins))
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 29 | n = int(input()) i = 0 c = 0 bins = {} while c < n: i += 1 b = bin(i).count('1') c += b bins[i] = b x = c - n if x == 0: print(len(bins)) print(*reversed(bins)) else: delete = [] for i, b in reversed(bins.items()): if b <= x: x -= b delete.append(i) if x == 0: break for key in delete: del bins[key] print(len(bins)) print(*reversed(bins)) |