#K8891. Nearest Prime Finder

    ID: 37413 Type: Default 1000ms 256MiB

Nearest Prime Finder

Nearest Prime Finder

Given a positive integer ( n ), find the prime number that is closest to ( n ). A prime number is an integer greater than 1 that has no divisors other than 1 and itself, i.e. it satisfies ( n > 1 ) and for every integer ( d ) with ( 2 \le d \le n-1 ), ( d ) does not divide ( n ). If ( n ) is prime, output ( n ). In case there is a tie (i.e. two prime numbers are equidistant from ( n )), output the smaller one.

For example, if ( n = 10 ), the prime numbers close to 10 are 7, 11, and 13. Since 11 is the closest, the output should be 11.

inputFormat

A single positive integer ( n ) is given via standard input. You may assume ( 1 \le n \le 10^9 ).

outputFormat

Output a single prime number to standard output, which is the closest prime number to ( n ). If there is a tie between two primes, output the smaller one.## sample

10
11

</p>