binary_weights = [1] list1 = [1] while len(binary_weights) < 2 << 15: binary_weights.extend( [bw for bw in binary_weights[len(binary_weights)//2:]] + [bw + 1 for bw in binary_weights[len(binary_weights)//2:]]) binary_weights_partial_sums = [] sum = 0 for bw in binary_weights: sum += bw binary_weights_partial_sums.append(sum) n = int(input()) starting_number = -1 number_to_remove = 0 for i, bws in (enumerate(binary_weights_partial_sums)): if n <= bws: starting_number = i + 1 diff = bws - n break if (diff > 0): for i, bws in reversed(list(enumerate(binary_weights[:starting_number]))): if bws == diff: number_to_remove = i + 1 break final_list = list(range(starting_number, number_to_remove, -1)) + list(range(number_to_remove - 1, 0, -1)) print(len(final_list)) print(" ".join(map(str, final_list)))
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 32 33 34 35 | binary_weights = [1] list1 = [1] while len(binary_weights) < 2 << 15: binary_weights.extend( [bw for bw in binary_weights[len(binary_weights)//2:]] + [bw + 1 for bw in binary_weights[len(binary_weights)//2:]]) binary_weights_partial_sums = [] sum = 0 for bw in binary_weights: sum += bw binary_weights_partial_sums.append(sum) n = int(input()) starting_number = -1 number_to_remove = 0 for i, bws in (enumerate(binary_weights_partial_sums)): if n <= bws: starting_number = i + 1 diff = bws - n break if (diff > 0): for i, bws in reversed(list(enumerate(binary_weights[:starting_number]))): if bws == diff: number_to_remove = i + 1 break final_list = list(range(starting_number, number_to_remove, -1)) + list(range(number_to_remove - 1, 0, -1)) print(len(final_list)) print(" ".join(map(str, final_list))) |