n = int(input()) digits_sum = [0, 1] step = [1] for i in range(2, 21): first_list = step second_list = [ x+1 for x in first_list ] step = first_list + second_list digits_sum += step prefix_sum = [0] * 1000001 target = 0 for i in range(1, 1000001): next_sum = prefix_sum[i-1] + digits_sum[i] prefix_sum[i] = next_sum if next_sum >= n: target = i break target_sum = prefix_sum[target] diff_sum = target_sum - n diff_value = len(digits_sum[:target]) - digits_sum[:target][::-1].index(diff_sum) - 1 sequence = [ str(x) for x in range(target, 0, -1) if x != diff_value] print(len(sequence)) print(" ".join(sequence))
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 | n = int(input()) digits_sum = [0, 1] step = [1] for i in range(2, 21): first_list = step second_list = [ x+1 for x in first_list ] step = first_list + second_list digits_sum += step prefix_sum = [0] * 1000001 target = 0 for i in range(1, 1000001): next_sum = prefix_sum[i-1] + digits_sum[i] prefix_sum[i] = next_sum if next_sum >= n: target = i break target_sum = prefix_sum[target] diff_sum = target_sum - n diff_value = len(digits_sum[:target]) - digits_sum[:target][::-1].index(diff_sum) - 1 sequence = [ str(x) for x in range(target, 0, -1) if x != diff_value] print(len(sequence)) print(" ".join(sequence)) |