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

View as PDF

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

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig
##### 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 .

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: .

#### Sample Input

0
1
2
3
5

#### Sample Output

1
1
2
4
4