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 Rust (1.15.1) (judge verdict: Accepted)

use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn is_prime(x: i64) -> bool {
    let mut is_p = true;
    //2未満は素数でない
    if x < 2 {
        is_p = false;
    //2は素数
    } else if x == 2 {
        is_p = true;
    //2の倍数は素数でない
    } else if x % 2 == 0{
        is_p = false;
    } else {
        //3から(i*i <= x) まで2ずつ増やしながらxを割り切れるか判定、割り切れる値があれば素数でない。
        //(i*i <= x)は√xの範囲と同値 O(√N)
        let mut counter = Some(3);
        while let Some(i) = counter {
            if i*i <= x {
                if x % i == 0 {
                    is_p = false;
                    counter = None;
                }else{
                    counter = Some(i+2);
                }
            } else{
                counter = None;
            }
        }
    }
    is_p
} 

//https://qiita.com/jin237/items/d544edcdfc7a08fa6998
//https://qiita.com/xryuseix/items/7e9b4c6f12d001a0c0db
fn main() {
    let mut a: i64 = read();

    loop{
        if is_prime(a) {
            println!("{}", a);
            break;
        }
        a += 1;
    }
}