#C5881. Single Peak Numbers
Single Peak Numbers
Single Peak Numbers
Given a positive integer (X), find all single peak numbers in the range ([1, X]). A number is considered a single peak number if its binary representation has exactly one '1' and at least one trailing zero. In other words, a number (n) is a single peak number if and only if it can be expressed in the form [ n = 10^k \quad \text{(in binary)}\quad \text{for some integer } k \ge 1. ] This essentially means that the number is a power of two greater than 1. For example, for (X=10), the single peak numbers are 2, 4, and 8.
inputFormat
The input consists of a single integer (X) (where (X \ge 0)) provided via standard input.
outputFormat
Output all the single peak numbers in ascending order that lie in the range ([1, X]) as space-separated integers to standard output. If there are no such numbers, print an empty line.## sample
5
2 4