DWITE '09 R5 #2 - Round to Second Prime

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, 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 5 \leq N \leq 100

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 r(7) = 3.

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.