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

View as PDF

Submit solution

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 0 \leq N \leq 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, \ldots, 2^n.

Sample Input


Sample Output


Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0) Problem Resource: DWITE


There are no comments at the moment.