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 C# (.NET Core 3.1.201) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
 
class Program
{
    public static readonly int[] Coefs = {4, 2, 4, 2, 4, 6, 2, 6};
 
    private static void Main()
    {
        var x = int.Parse(Console.ReadLine());
        var primes = Sieve(100003);
        var answer = primes.First(prime => prime >= x);
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();
    }
 
    public static List<int> Sieve(int max)
    {
        var isPrimes = Enumerable.Repeat(true, max + 1).ToArray();
 
        for (var i2 = 4; i2 <= max; i2 += 2) isPrimes[i2] = false;
        for (var i3 = 9; i3 <= max; i3 += 6) isPrimes[i3] = false;
        for (int i5 = 25, x = 4; i5 <= max; i5 += 5 * (x = 6 - x)) isPrimes[i5] = false;
 
        var iCoefIndex = 7;
        for (var i = 7; i * i <= max; i += Coefs[iCoefIndex])
        {
            if (!isPrimes[i])
            {
                iCoefIndex = iCoefIndex == 7 ? 0 : iCoefIndex + 1;
                continue;
            }
 
            var jCoefIndex = iCoefIndex;
            for (var j = i * i; j <= max; j += i * Coefs[jCoefIndex])
            {
                isPrimes[j] = false;
                jCoefIndex = jCoefIndex == 7 ? 0 : jCoefIndex + 1;
            }
 
            iCoefIndex = iCoefIndex == 7 ? 0 : iCoefIndex + 1;
        }
 
        return Primes(max, isPrimes);
    }
 
    public static List<int> Primes(int max, bool[] isPrimes)
    {
        var primes = new List<int>();
        if (max < 2) return primes;
        primes.Add(2);
        if (max < 3) return primes;
        primes.Add(3);
        if (max < 5) return primes;
        primes.Add(5);
        if (max < 7) return primes;
 
        var iCoefIndex = 7;
        for (var i = 7; i <= max; i += Coefs[iCoefIndex])
        {
            if (isPrimes[i])
                primes.Add(i);
            iCoefIndex = iCoefIndex == 7 ? 0 : iCoefIndex + 1;
        }
 
        return primes;
    }
}