def get_strength(a): return bin(a).count("1") def main(): value = int(input()) strength_sum = 0 result = [] counter = 0 while strength_sum < value: counter += 1 strength_sum += get_strength(counter) result.append(counter) final_result = [] for x in reversed(result): if strength_sum - get_strength(x) >= value: strength_sum -= get_strength(x) else: final_result.append(x) print(f"{len(final_result)}\n{' '.join([str(x) for x in final_result])}\n") if __name__ == '__main__': main()
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 | def get_strength(a): return bin(a).count("1") def main(): value = int(input()) strength_sum = 0 result = [] counter = 0 while strength_sum < value: counter += 1 strength_sum += get_strength(counter) result.append(counter) final_result = [] for x in reversed(result): if strength_sum - get_strength(x) >= value: strength_sum -= get_strength(x) else: final_result.append(x) print(f"{len(final_result)}\n{' '.join([str(x) for x in final_result])}\n") if __name__ == '__main__': main() |