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 (Python):
n = int(input())
count = 0

def prime(n):
    if n == 2:
        return True
    else:
        i = 2
        while i ** 2 <= n:
            if n % i == 0:
                return False
            i += 1
        return True
i = n
while not prime(i):
    i += 1
print(i)

Solution (Python):
X = int(input())
if X == 2:
  print(X)
while X > 2:
  if X % 2 == 0:
    
    X += 1
  else:
    n = 3
    while n * n <= X:
      if X % n == 0:
        
        X += 1
        break
      n += 1
    else:
      print(X)
      break

Solution (Python):
import math
X = int(input())
if X == 2:
    print(2)
else:
    is_end = False
    while not is_end:
        is_end = True
        for i in range(1, X // 2):
            if math.gcd(X, i) != 1:
                is_end = False
                X += 1
                break
    print(X)

Solution (Python):

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


def main():
    X = int(input())

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


if __name__ == '__main__':
    main()

Solution (Python):
from math import sqrt
x = int(input())

while True:
    f = 1
    s = int(sqrt(x))
    for i in range(2, s+1):
        if x % i == 0:
            f = 0
            break
    if f == 1:
        print(x)
        break
    x += 1

Solution (Python):
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

x = int(input())

for i in range(x, 10**5 + 4):
    if is_prime(i) == True:
        print(i)
        exit()

Solution (Python):
X=int(input())

def is_prime(x):
    if x<=1:
        return False
    
    for i in range(2,int(-(-x**0.5//1))):
        if x%i==0:
            return False
    
    return True

p=X
while not is_prime(p):
    p+=1

print(p)

Solution (Python):
import math

x=int(input())

if x==2:
    print(2)
    exit()

x=x//2*2+1
i=x
while 1:
    flag=True
    for j in range(2,int(i**0.5)+1):
        if i%j==0:
            flag=False
            break
    if flag:
        break
    i+=1

print(i)

Solution (Python):

import sys


def solve(X: int):
    if X == 2:
        print(X)
        return
    n = X -1
    while True:
        n += 1
        if n % 2 == 0:
            continue
        f = True
        for i in range(3, (n//2)+1, 2):
            if n % i == 0:
                f = False
                break
        if f:
            print(n)
            break

    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  
    solve(X)

if __name__ == '__main__':
    main()

Solution (Python):
import math
x = int(input()) -1
def is_prime(x):
    prime = True
    for i in range(2,int(math.sqrt(x))):
        if x % i == 0:
            prime = False
            break
    return prime

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

Solution (Python):
x = int(input())
ans = 0
for i in range(x, 10000000):
    is_prime_bool = True
    for j in range(2, i - 1):
        if i % j == 0:
            is_prime_bool = False
            break
    if is_prime_bool:
        print(i)
        break

Solution (Python):

X = int(input())

sosu_list = [2]

for num in range(3,X+1,2):
    if all(num%sosu != 0 for sosu in sosu_list):
        sosu_list.append(num)

if X == sosu_list[-1]:
    print(X)
else:
    if X % 2 ==0:
        X+=1
    while True:
        if all(X%sosu != 0 for sosu in sosu_list):
            print(X)
            break
        X += 2

Solution (Python):
from math import sqrt
x = int(input())

while True:
    isP = True
    for i in range(2, int(sqrt(x))):
        if x % i == 0:
            isP = False
            break
    if isP:
        print (x)
        break
    x += 1

Solution (Python):
x = int( input() )

def prime_test( n ):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    for k in range( 3, int( n ** 0.5 ) + 1 ):
        if n % k == 0:
            return False
    return True

while True:
    if prime_test( x ) == True:
        print( x )
        break
    x += 1

Solution (Python):
from bisect import bisect_left

n = int(input())
hurui = [True for _ in range(100010)]
prime_lst = []
for i in range(2, 100010):
  if not hurui[i]:
    continue
  prime_lst.append(i)
  for j in range(i * i, 100010, i):
    hurui[j] = False

pos = bisect_left(prime_lst, n)
print(prime_lst[pos])

Solution (Python):
x = int(input())
ans = 0
if x == 2:
    ans = 2
elif x == 3:
    ans = 3
else:
    for i in range(x,100004):
        check = True
        root = int(i ** 0.5) + 1
        for j in range(2,root):
            if i % j == 0:
                check = False
                break
            else:
                continue
        if check:
            ans = i
            break
print(ans)

Solution (Python):
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

x=int(input())
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

ans=x
while not is_prime(ans):
    ans+=1
print(ans)

Solution (Python):

x= int(input())

def prime_check(num,count):
    while True:
        while num % count == 0:
            num = num + 1
            count = 2
        if num <= count**2:
            print(num)
            break
        else:
            count = count + 1

if x==2 :
    print (2)
else:
    prime_check(x,2)

Solution (Python):

import sys
sys.setrecursionlimit(1000000)

x= int(input())

def prime_check(num,count):
    if (num % count) != 0:
        if num <= count**2:
            print(num)
        else:
            prime_check(num,count+1)
    else :
        prime_check(num+1,2)

if x==2 :
    print (2)
else:
    prime_check(x,2)

Solution (Python):
MAX=200000
def get_prime(x):
  is_prime = [True] * 200000
  for i in range(2,MAX):
    if is_prime[i] and i >= x:
      return i
    elif is_prime[i]:
      for j in range(2 * i, MAX, i):
        is_prime[j] = False

print(get_prime(int(input())))

Solution (Python):
primeornot=[True]*(10**5*2)
for i in range(2,10**5):
    if primeornot[i]==True:
        j=2*i
        while j<10**5*2:
            primeornot[j]=False
            j+=i
x=int(input())
for i in range(x,10**5*2):
    if primeornot[i]==True:
        print(i)
        break

Solution (Python):
x=int(input())
flag=1
prime=[]
num=2
while flag!=0:
    f=0
    for p in prime:
        if num%p==0:
            f=1
            break
    if f==0:
        prime.append(num)
        if x<=num:
            flag=0
    if flag==0:
        break
    else:
        num+=1
print(num)

Solution (Python):
X = int(input())

if X == 2:
    print(2)
    exit()
    
for i in range(X,2*X):
    for j in range(2,i):
        if i % j == 0:
            break
        if j == i-1:
            print(i)
            exit()

Solution (Python):
X = int(input())

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

prime = get_sieve_of_eratosthenes_new(10**6)
for num in prime:
    if num >= X:
        print(num)
        break

Solution (Python):
x = int(input())
if x == 2:
    print(2)
    exit()
while True:
    flg = 0
    for i in range(2,int(x**0.5)+1):
        if x%i == 0:
            flg += 1
        if i == int(x**0.5) and flg == 0:
            print(x)
            exit()
    x += 1

Solution (Python):
X = int(input())

def prime_judge(N):
  K = 2
  ans = True
  while K*K <= N:
    if N%K == 0:
      ans = False
      break
    else:
      K += 1
  return ans

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

Solution (Python):
x = int(input())
while True:
  flg = True
  for i in range(2,x):
    if x % i == 0:
      flg = False
      break
  if flg == True: break
  x += 1
print(x)

Solution (Python):
X = int(input())


while True:
  a = []
  for i in range(2,X):
    if X % i == 0:
      a.append(0)
      break
    else:
      a.append(1)
  
  if 0 in a:
    X += 1
  else:
    break

print(X)

Solution (Python):
x = int(input())

def isprime(s):
  if s>2 and s%2==0:
    return False
  else:
    flg = True
    for i in range(3, s//2+1, 2):
      if s%i == 0:
        flg = False
        break
    return flg

for i in range(x, 10**6):
  if isprime(i) == True:
    print(i)
    break

Solution (Python):
x = int(input())

def prime_check(n):
    f = 3
    while f * f <= n:
        if n % f == 0:
            return False
        else:
            f += 2
    else:
        return True

if x != 2:
    if x % 2 == 0:
        x += 1
    while 1:
        if prime_check(x) == True:
            print(x)
            break
        else:
            x += 2
else:
    print(2)

Solution (Python):
x = int(input())
n = int(x**0.5)

if x==2 or x==3:
    print(x)
else:
    while True:
        for i in range(2,n+1,1):
            if x%i==0:
                break
        else:
            print(x)
            break
        x += 1

Solution (Python):
X=int(input())

p=[True for _ in range(0,200000+1)]
p[0]=False
p[1]=False
for i in range(2,200000+1):
    if p[i]==False:
        continue
    for j in range(2,200000//i):
        p[i*j]=False

while p[X]==False:
    X+=1
print(X)

Solution (Python):
import math
X = int(input())
if X == 2:
    print(2)
else:
    is_find = False
    while not is_find:
        for i in range(2, X//2):
            is_find = True
            if math.gcd(X, i) != 1:
                is_find = False
                X += 1
                break
        rst = X
    print(rst)

Solution (Python):

from math import sqrt

def main():
    X = int(input())

    for i in range(X, 100004):
        tmp = int(sqrt(i))
        flg = False
        for j in range(2, tmp + 1):
            if (i % j == 0):
                flg = True
                break
        if flg == False:
            ans = i
            break

    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
X = int(input())
flag = 0
if X == 2 or X == 3:
    flag = 1
    print(X)
while flag == 0 :
    for i in range(2,int(X**0.5)+1):
        if X%i == 0:
            X += 1
            break
        else:
            if i == int(X**0.5):
                flag = 1
                print(X)

Solution (Python):
x = int(input())
num=2
while num<x:
  if x%num==0:
    x+=1
    num=2
  else:
    num+=1
print(x)

Solution (Python):
x = int(input())

ans = x
past = int(ans**0.5)
divisor = [i for i in range(1, past+1, 1) if x%i == 0]
while len(divisor) != 1:
    if ans%2 == 0:
        ans += 1
    else:
        ans += 2
    root = int(ans**0.5)
    divisor = [j for j in range(1, root+1, 1) if ans%j == 0]

print(ans)

Solution (Python):
p = int(input())
while True:
  q = int(p**0.5)
  for i in range(2, q+1):
    if p%i == 0:
      p += 1
      break
  else:
    print(p)
    break

Solution (Python):
x=int(input())
m=2*(10**5)
lis=[True for i in range(m)]
i=2
while i*i<=m:
    if lis[i]:
        for j in range(2*i,m,i): lis[j]=False
    i+=1
while True:
    if lis[x]:
        print(x)
        break
    x+=1

Solution (Python):
def is_prime(x):
  k = 2
  while k * k <= x:
    if x % k == 0:
      return False
    k += 1
  return True

x = int(input())
while True:
  if is_prime(x):
    print(x)
    break
  else:
    x+=1

Solution (Python):
x = int(input())
def f():
    for i in range(x, 10**10):
        c = 0
        for j in range(2, i):
            if i%j != 0:
                c += 1
                if c == i-2:
                    return i
            else:
                break
if x == 2:
    print(2)
else:
    print(f())

Solution (Python):
import sys
N = int(input())
if N == 2:
  print(2)
  sys.exit()
n = N-1
Flag = True
while Flag:
  n += 1
  for i in range(2,int(n**0.5)+1):
    if n%i == 0:
      break
    if i == int(n**0.5) and n%i != 0:
      Flag = False
  
print(n)

Solution (Python):
import math

def is_prime(x):
	for i in range(2, int(math.sqrt(x))):
		if x % i == 0:
			return False
	return True

x = int(input())
while(not is_prime(x)):
	x += 1
print(x)

Solution (Python):
X=int(input())
flag=0

if X==2 or X==3:
	flag=1

while flag==0:
	for k in range(2,int(X**0.5)+1):
		if k==int(X**0.5) and X%k!=0:
			flag=1
		
		if k>2 and k%2==0:
			continue
		elif k>3 and k%3==0:
			continue
		elif X%k==0:
			break
	
	if flag==0:X=X+1	
		
print(X)

Solution (Python):

from math import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement


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

x = int(input())
while True:
    if is_prime(x):
        print(x)
        break
    else:
        x+=1

Solution (Python):

import sys
from itertools import chain
import numpy as np


def solve(X: int):
    if X <= 2:
        return 2
    flags = np.array([True for i in range(3, X + 100, 2)])
    for i in range(len(flags)):
        if flags[i]:
            prime = i * 2 + 3
            flags[i::prime] = False
            if prime >= X:
                return prime




def main():
    X = int(input())  
    answer = solve(X)
    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
from itertools import chain
import numpy as np


def solve(X: int):
    if X <= 2:
        return 2
    flags = np.array([True for i in range(3, X + 112, 2)])
    for i in range(len(flags)):
        if flags[i]:
            prime = i * 2 + 3
            flags[i::prime] = False
            if prime >= X:
                return prime




def main():
    X = int(input())  
    answer = solve(X)
    print(answer)


if __name__ == "__main__":
    main()

Solution (Python):
import math

def isPrime(n):
    if n < 2:
        return False
    else:
        divisors = []
        tem = []
        for p in range(1,math.ceil(n**(1/2)+1)):
            if n % p == 0:
                divisors.append(p)
        
        for divisor in divisors:
            tem.append(n//divisor)
        
        divisors = list(set(sorted(divisors + tem)))
        
        if len(divisors) == 2:
            return True
        else:
            
            return False

X = int(input())

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

Solution (Python):
def main():
    X = int(input())
    if X == 2:
        print(2)
        exit()
    if X % 2 == 0:
        X += 1
    while True:
        flag = True
        for i in range(3, X, 2):
            if X % i == 0:
                flag = False
                break
        if flag is True:
            print(X)
            break
        else:
            X += 2


if __name__ == '__main__':
    main()

Solution (Python):
import math
x = int(input())

while True:
  a = int(math.sqrt(x))
  for y in range(2,a+1):
    if x % y == 0:
      break
  else:
    ans = x
    break
  x += 1

  
print(ans)

Solution (Python):
import sys
import copy
X = int(input())
while True:
    b = False
    for i in range(2,X):
        if X%i == 0:
            b = True
            break

    if b == False:
        print(X)
        sys.exit(0)
    else:
        X+=1

Solution (Python):
n = int(input())
 
def p(x):
  if x == 2:
    return True
  for i in range(2,x//2):
    if x % i == 0:
      return False
  return True
 
for i in range(n,2*n):
  if p(i):
    print(i)
    break

Solution (Python):
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    X=I()
    
    
    n = 2*(10**6)

    
    is_prime = [True]*(n+1)
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i

    table = [ i for i in range(1, n+1) if is_prime[i-1]]
    
    for i in table:
        if i>=X:
            print(i)
            exit()

main()

Solution (Python):

import sys
input=sys.stdin.readline

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

def main():
    x = int(input())

    for i in range(x,100004):
        if is_prime(i)==True:
            print(i)
            break

if __name__=="__main__":
    main()

Solution (Python):
x = int(input())
flag = True
while flag:
    flag = False
    for i in range(2, x):
        if x%i == 0:
            flag = True
            x += 1
            break
print(x)

Solution (Python):
import math

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

n = int(input())
while True:
  if prime(n):
    break
  else:
    n += 1
print(n)

Solution (Python):
from sys import exit
import math
import collections
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

x = ii()
while 1:
    cnt = 0
    for i in range(2,math.ceil(x**(1/2)),1):
        if x % i == 0:
            cnt = 1
            break
    if cnt == 0:
        print(x)
        exit()
    x += 1

Solution (Python):
import math
def isprime(n):
  if n == 2:
    return True
  elif n % 2 == 0:
    return False
  else:
    for i in range(3,math.ceil(math.sqrt(n))+1,2):
      if n % i == 0:
        return False
    return True

x = int(input())
ans = 0
if x == 2:
  ans = 2
else:
  if x % 2 == 0:
    st = x+1
  else:
    st = x
  for i in range(st,100001):
    if isprime(i) == True:
      ans = i
      break
  if ans == 0:
    ans = 100003
print(ans)

Solution (Python):
def prime(n):
    if n <= 1:
        return False
    for i in range(2, n):
        if n % i == 0:
            return False
    return True


X = int(input())
while True:
    if prime(X):
        break
    else:
        X += 1
print(X)

Solution (Python):
x = int(input())

def hantei(x):
  p = []
  for i in range(2,int(x**(1/2))+1):
    if (x % i) == 0:
      return False
  else:
    return True
  
while 1:
  if hantei(x):
    print(x)
    break
  else:
    x+=1

Solution (Python):
X = int(input())
a = 0
if X == 2 or X == 3:
  print(X)
  exit()
if X % 2 == 0:
  X += 1
for i in range(X , 10 ** 6, 2):
  for j in range(3,i,2):
    a = i % j
    if a == 0:
      break
  if a != 0 :
    print(i)
    exit()

Solution (Python):
import sys
def Prime(x):
  for i in range(2, x):
    if(x%i==0):
      return False
  return True

if (__name__=='__main__'):
  X = int(input())
  i = 0
  while True:
    if Prime(X+i):
      print(X+i)
      sys.exit()
    i += 1

Solution (Python):
x=int(input())
while True:
  flag=0
  for i in range(2,int(x**0.5)+2):
    if x%i==0:
      flag=1
      break
    else:
      continue
  if x==2:
    flag=0
  if flag==0:
    print(x)
    break
  else:
    x+=1

Solution (Python):

"""
Created on Tue Sep  8 20:37:12 2020

@author: liang
"""
import math
X = int(input())
N = int(math.sqrt(X))
lis = list(range(2,N+1))


ans = X 

while True:
    if all(ans%i != 0 for i in lis):
        print(ans)
        break
    
    ans += 1

Solution (Python):

"""
Created on Tue Sep  8 20:25:36 2020

@author: liang
"""

def Eratosthenes(x):
    lis = [int(i) for i in range(2,x+1)]
    
    res = list()
    while lis:
        a = lis.pop(0)
        res.append(a)
        lis = [i for i in lis if i%a != 0]
        
    return res

import math
X = int(input())
N = int(math.sqrt(X))
lis = Eratosthenes(N)


ans = X 

while True:
    if all(ans%i != 0 for i in lis):
        print(ans)
        break
    ans += 1