import sys def get_bit_count(value): n = 0 while value: n += 1 value &= value - 1 return n n = int(sys.stdin.readline()) s = 0 i = 1 last = {} last[0] = 0 while s < n: bits = get_bit_count(i) s += bits last[bits] = i i += 1 to_print = [x for x in range(1, i) if x != last[s - n]] print(len(to_print)) print(" ".join([str(p) for p in to_print[::-1]]))
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 | import sys def get_bit_count(value): n = 0 while value: n += 1 value &= value - 1 return n n = int(sys.stdin.readline()) s = 0 i = 1 last = {} last[0] = 0 while s < n: bits = get_bit_count(i) s += bits last[bits] = i i += 1 to_print = [x for x in range(1, i) if x != last[s - n]] print(len(to_print)) print(" ".join([str(p) for p in to_print[::-1]])) |