Question
Closest power
You're given a positive integer n, determine the closest number which is a power of 2. If two powers of 2 are equidistant from n, print the smaller one.
Input
Input contains an integer n (1 <= n <= 108).
Output
Print the closest power of 2. If two powers of 2 are equidistant from n, print the smaller one.
Example
Input 1
34
Output 1
32
Explanation
Closest power of two is 32 from this number.
Input 2
12
Output
8
Explanation
Closest powers of two are 8 and 16. Both have difference of 4. Hence the answer is the smaller one.
34
Output 1
32
Explanation
Closest power of two is 32 from this number.
Input 2
12
Output
8
Explanation
Closest powers of two are 8 and 16. Both have difference of 4. Hence the answer is the smaller one.