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



Sample input:
20


Sample output:
23

Submission status: Accepted

Solution code:



def get_prime(x):
    for i in range(2, x+1):
        amari = x%i
        #print(x,i, amari)
        if amari == 0:
            if i == x:
                return x
            else:
                return -1
        else:
            continue
    
    return x

X  = int(input())

flag = True
num = 0
answer = 0
while flag:
    v = X+num 
    if get_prime(v) > 0:
        flag = False
    num += 1

print(v)

Submission status: Accepted

Solution code:
X = int(input())
if X == 2:
    print(X)
    exit(0)
while 1:
    for i in range(2, X):
        if X % i == 0:
            break
        elif i == X - 1 and X % i != 0:
            print(X)
            exit(0)
    X += 1

Submission status: Accepted

Solution code:
n = int(input())

def is_prime(n):
    if n == 1:
        return False
    i = 2
    while(i * i <= n):
        if n % i == 0:
            return False
        i += 1
    return True

result = n
while(not is_prime(result)):
    result += 1

print(result)

Submission status: Accepted

Solution code:
from bisect import bisect_left

def get_primes(n):
    if not isinstance(n, int):
        raise TypeError('n is int-type.')
    if n < 2:
        raise ValueError('n is more than 2')
    
    from math import sqrt 
    def _sieve_of_eratosthenes(n):
        primes = []
        limit = sqrt(n)
        data = [i + 1 for i in range(1, n)]
        while True:
            p = data[0]
            if limit <= p:
                return primes + data
            primes.append(p)
            data = [e for e in data if e % p != 0]
    return _sieve_of_eratosthenes(n)

primes = get_primes(10**5 + 3)
print(primes[bisect_left(primes, int(input()))])

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

def get_primes(n):
    if not isinstance(n, int):
        raise TypeError('n is int-type.')
    if n < 2:
        raise ValueError('n is more than 2')
    
    from math import sqrt 
    def _sieve_of_eratosthenes(n):
        primes = []
        limit = sqrt(n)
        data = [i + 1 for i in range(1, n)]
        while True:
            p = data[0]
            if limit <= p:
                return primes + data
            primes.append(p)
            data = [e for e in data if e % p != 0]
    return _sieve_of_eratosthenes(n)

primes = get_primes(10**5 + 3)
print(primes[bisect_left(primes, int(input()))])

Submission status: Accepted

Solution code:
def is_prime(num):
    if num == 1:
        raise ValueError("error!")
    d = 2
    while d * d <= num:
        if num % d == 0:
            return False
        d += 1
    return True

n = int(input())
for i in range(n, n+1000):
    if is_prime(i):
        print(i)
        exit()

Submission status: Accepted

Solution code:
def is_prime(num):
    d = 2
    while d * d <= num:
        if num % d == 0:
            return False
        d += 1
    return True

n = int(input())
for i in range(n, n+1000):
    if is_prime(i):
        print(i)
        exit()