n = int(input()) bin_count = [] bin_prexif_sum = [0] i = 1 while True: bin_count.append(format(i, 'b').count('1')) bin_prexif_sum.append(bin_prexif_sum[-1] + bin_count[-1]) i += 1 if bin_prexif_sum[-1] > n: break bin_prexif_sum = bin_prexif_sum[1:] left = bin_prexif_sum[-1] - n seq = [] i = len(bin_prexif_sum) while i > 0: if bin_count[i - 1] == left: left = -1 else: seq.append(i) i -= 1 print(len(seq)) for x in seq: print(x, end=' ') print()
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 30 31 | n = int(input()) bin_count = [] bin_prexif_sum = [0] i = 1 while True: bin_count.append(format(i, 'b').count('1')) bin_prexif_sum.append(bin_prexif_sum[-1] + bin_count[-1]) i += 1 if bin_prexif_sum[-1] > n: break bin_prexif_sum = bin_prexif_sum[1:] left = bin_prexif_sum[-1] - n seq = [] i = len(bin_prexif_sum) while i > 0: if bin_count[i - 1] == left: left = -1 else: seq.append(i) i -= 1 print(len(seq)) for x in seq: print(x, end=' ') print() |