DWITE '09 R6 #2 - Round to power of two

View as PDF

Submit solution

Points: 3
Time limit: 2.0s
Memory limit: 64M

Problem type
DWITE Online Computer Programming Contest, April 2010, Problem 2

Yet another "round to arbitrary sequence" question — powers of 2. Given a non-negative integer, what is the closest integer that is also an integer power of 2? This one actually might have some potential application, as integer powers of 2 are represented by a single bit in a digital sequence — numbers that are the easiest to work with in digital circuits, so we might want to approximate some numbers to work with "easier" numbers instead.

The input will contain 5 lines, integers 0 \le N \le 65\,536.

The output will contain 5 lines, corresponding integers rounded to the closest integer power of 2. If there are two integers equally far away, then use the higher value for the answer.

The sequence starts as: 1, 2, 4, 8, 16, 32, \dots, 2^n.

Sample Input

0
1
2
3
5

Sample Output

1
1
2
4
4

Problem Resource: DWITE

Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported

Comments

There are no comments at the moment.