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)

/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

pub struct Sieve {
    primes: Vec<u64>,
    tbl: Vec<u64>,
}
impl Sieve {
    pub fn new(n: u64) -> Sieve {
        let sz: usize = (n + 1) as usize;
        let mut primes = Vec::new();
        let mut tbl = vec![0; sz];
        tbl[0] = 0;
        tbl[1] = 0;
        for i in 2..sz {
            if tbl[i] != 0 {
                continue;
            }
            primes.push(i as u64);
            tbl[i] = i as u64;
            let mut j = i * i;
            while j < sz {
                if tbl[j] == 0 {
                    tbl[j] = i as u64;
                }
                j += i;
            }
        }
        Sieve {
            primes: primes,
            tbl: tbl,
        }
    }
    pub fn primes(&self) -> &Vec<u64> {
        &self.primes
    }
    pub fn is_prime(&self, x: u64) -> bool {
        x > 1 && self.tbl[x as usize] == x
    }
    pub fn factorization(&self, x: u64) -> Vec<(u64, u64)> {
        let mut mx = x;
        let mut fl = Vec::new();
        while mx > 1 {
            let fx = self.tbl[mx as usize];
            fl.push(fx);
            mx /= fx;
        }
        if fl.is_empty() {
            return Vec::new();
        }
        let mut res = vec![(fl[0], 0)];
        for p in &fl {
            let l = res.len() - 1;
            let last = res[l];
            if last.0 == *p {
                res[l].1 += 1;
            } else {
                res.push((*p, 1));
            }
        }
        res
    }
}

fn main() {
    input! {
        x: u64
    }
    let s = Sieve::new(100003);
    for i in x.. {
        if s.is_prime(i) {
            println!("{}", i);
            return;
        }
    }
}
/* vim:set foldmethod=marker: */