Problem:
Score: 300 points

Problem Statement

Find the minimum prime number greater than or equal to X.

Notes

A prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.

For example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.

Constraints

2 \le X \le 10^5

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the minimum prime number greater than or equal to X.

Sample Input 1

20

Sample Output 1

23

The minimum prime number greater than or equal to 20 is 23.

Sample Input 2

2

Sample Output 2

2

X itself can be a prime number.

Sample Input 3

99992

Sample Output 3

100003

Solution in PHP7 (7.0.15) (judge verdict: Accepted)

<?php
$x = (int)trim(fgets(STDIN));

if ($x === 2) {
	echo $x;
	exit();
}
if ($x % 2 === 0) {
	$x += 1;
}
while (true) {
	$p_list = primefactors($x);
	if (isset($p_list[$x])) {
		echo $x;
		exit();
	}
	$x += 2;
}




// 素因数分解
function primefactors($n){
	// １は確実に1回
	$result = [1 => 1];
	// 偶数なら2を素因数に追加
	while ($n % 2 === 0) {
		$n = (int)floor($n/2);
		if (isset($result[2])) {
			$result[2] += 1;
		}else{
			$result[2] = 1;
		}
	}
	// ３以上の奇数について素因数と乗数を計算（割残し$nの平方根にあたる数まで確認すればOK）
	for ($i=3; $i*$i <= $n; $i+=2) { 
		while ($n % $i === 0) {
			$n = (int)floor($n/$i);
			if (isset($result[$i])) {
				$result[$i] += 1;
			}else{
				$result[$i] = 1;
			}
		}
	}
	// 3以上の割残しがある場合、その数は素数なので素因数として追加する（例：26の素因数13とか）
	if ($n > 2) {
		$result[$n] = 1;
	}
	return $result;
}