## DWITE '09 R5 #2 - Round to Second Prime

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, March 2010, Problem 2

More from the series of round to closest obscure function — round to the closest second prime. That is, "round" an integer to a closest prime number such that there is exactly one other prime number between the original input and the result. If the input integer itself is a prime, it is still rounded (the requirement of having a prime in between). If there are two primes equally far away that both satisfy the condition, then the larger one is the answer.

The input will contain 5 lines, integers

The output will contain 5 lines, integer answers to corresponding lines of input.

Example: input is 7 (which incidentally is a prime). The two primes around it are 5 and 11. The two second primes around that are 3 and 13. 3 is closer to 7 than 13 is, so .

#### Sample Input

5
6
7
8
9

#### Sample Output

2
3
3
5
13