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:
X = int(input())
i = 0
while True:
    y = True
    for n in range(X+i-2):
        if (X+i)%(n+2) == 0:
            y = False
            break
    if y == True:
        print(X+i)
        break
    i += 1

Submission status: Accepted

Solution code:
def p(x):
    res = 0
    y = 2
    while y*y <= x:
        while x % y == 0:
            res += 1
            x //= y
        y += 1
    if x > 1:
        res += 1
    return res
x = int(input())

while 1:
    if p(x)==1:
        print(x)
        quit()
    x+=1

Submission status: Accepted

Solution code:
from math import sqrt
def prime(x):
  for i in range(2,int(sqrt(x))+1):
    if x%i==0:
      return False
  else:
    return True
n=int(input())
j=0
while True:
    
    if prime(n+j):
      print(n+j)
      break
    j+=1

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

X = int(input())

ans = X
while True:
    N = int(ans**0.5) + 1
    flag = True
    for i in range(2,N):
        if ans%i==0:
            flag = False
            break
    if flag:
        break
    ans += 1
print(ans)

Submission status: Accepted

Solution code:
import math 

def sieve_of_eratosthenes(n): 
    candidate = [i for i in range(2, n+1)] 
    prime = []
    limit = math.sqrt(n) + 1 

    while True:
        p = min(candidate) 
        if limit <= p:
            prime.extend(candidate) 
            break
        prime.append(p) 

        candidate = [i for i in candidate if i % p != 0]

    return prime

n = 100003

so_list = sieve_of_eratosthenes(n)
N = int(input())

for one in so_list:
    if one>=N:
        print(one)
        break

Submission status: Accepted

Solution code:
x = int(input())
from math import ceil, sqrt
def eratosthenes(n):
    l = [1 for i in range(n+1)]
    l[0] = l[1] = 0
    for i in range(2, ceil(sqrt(n))):
        if l[i] == 0: continue
        for j in range(i*2, n+1, i):
            l[j] = 0
    return l


l = eratosthenes(2*10**5)


while True:
    if l[x]:
        break
    x+=1
print(x)

Submission status: Accepted

Solution code:
X = int(input())


def is_prime(n):
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True


while True:
    if is_prime(X):
        print(X)
        break
    else:
        X += 1

Submission status: Accepted

Solution code:
def checkPrime(num) :
    flag = 0
    for i in range(2,num) :
        if num % i == 0 :
            flag = 1
            break
    if (flag) :
        return False
    else :
        return True
num = int(input())
i = num
while(True) :
    res = checkPrime(i)
    if (res) :
        print(i)
        break
    else :
        pass
    i += 1

Submission status: Accepted

Solution code:
def isPrime(n):
    if n < 2:
        # 2未満は素数でない
        return False
    if n == 2:
        # 2は素数
        return True
    for p in range(2, n):
        if n % p == 0:
            # nまでの数で割り切れたら素数ではない
            return False
    # nまでの数で割り切れなかったら素数
    return True


x = int(input())

for n in range(x, 10**6):
    if n > 2 and n % 2 == 0:
        continue

    if isPrime(n):
        break

print(n)

Submission status: Accepted

Solution code:
import math

x = int(input())

def is_prime(n):
    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False
    return True

for i in range(x, 100004):
    prime = is_prime(i)
    if prime:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import math

def prime(k):
    if k == 2:
        return True
    if k == 1 or k % 2 == 0:
        return False
    else:
        for d in range(3, math.floor(math.sqrt(k)) + 1, 2):
            if k % d == 0:
                return False
        return True

n = int(input())

while not prime(n):
    n+=1
print(n)

Submission status: Accepted

Solution code:
import math

def is_prime(n):
  if n == 1: return False

  for k in range(2, int(math.sqrt(n)) + 1):
    if n % k == 0:
      return False

  return True

n = int(input())

if n % 2 == 0:
  if n == 2:
    print(n)
    exit()
  n += 1

while True:
  if is_prime(n):
    break
  n += 2
print(n)