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:
import math

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

Submission status: Accepted

Solution code:
from math import sqrt
X=int(input())

def checkprime(x):
  for i in range(1,int(sqrt(x))+1,2):
    #print(i)
    if i == 1:
      continue
    if X%i==0:
      return False
  return True

if X<=2:
  print(X)
  exit()

if X%2==0:
  X+=1
while(1):
  if checkprime(X):
    print(X)
    break
  else:
    X+=2

Submission status: Accepted

Solution code:
X = int(input())
while True:
    isPrime = True
    f = 2
    while f*f<=X and isPrime:
        if X%f==0: isPrime=False
        f+=1
    if isPrime:
        print(X)
        exit()
    X+=1

Submission status: Accepted

Solution code:
from math import sqrt
n=int(input())
for i in range(n,n*10000):
    a=1
    if i%2!=0:
        a=0
        for j in range(3,round(sqrt(n))+1,2):
            if i%j==0:
                a+=1
                break
    elif i==2:
        print(2)
        break
    if a==0:
        print(i)
        break

Submission status: Accepted

Solution code:
n = int(input())
i = 2

while True:
    if n == i:
        print(n)
        break
        
    elif n % i == 0 and i != n:
        n += 1
        i = 2
        
    else:
        i += 1

Submission status: Accepted

Solution code:
def is_prime(x):
    if x == 1:
        return(False)
    y = 2
    while y < x:
        if x%y == 0:
            return(False)
        y += 1
    return(True)
 
n = int(input())
while True:
    if is_prime(n):
        print(n)
        break
    n += 1

Submission status: Accepted

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

n = int(input())
while True:
  if is_prime(n):
    print(n)
    quit()
  n += 1

Submission status: Accepted

Solution code:
input_num = input()
number = int(input_num)
target = number
while 1:
    count = 0
    for i in range(target+1):
        if i == 0:
            continue
        if target%i == 0:
            count += 1
    if count == 2:
        break
    target += 1

print(target)

Submission status: Accepted

Solution code:
import math
import sys

X = int(input())

while True:
    flag = 0
    for i in range(2, int(math.sqrt(X)+1)):
        if X % i == 0:
            flag = 1
            break

    if flag == 0:
        print(X)
        sys.exit()

    else:
        X += 1

Submission status: Accepted

Solution code:
import math
DBG = False
def is_prime(N):
    tf = True
    for i in range(2, int(math.sqrt(N))):
        if N%i == 0:
            tf = False
    return tf

X = int(input())
while(is_prime(X)==False):
    X += 1
    if DBG:
        print("%7d is Prime: %s"%(X, str(is_prime(X))))
print(X)

Submission status: Accepted

Solution code:
x = int(input())

while x < 1000000:
  y = 0

  for i in range(x//2):
    if x % (i+1) == 0:
      y += 1

  if y == 1:
    print(x)
    break

  else:
    x = x + 1

Submission status: Accepted

Solution code:
def main():
    X = int(input())
    i = 2
    while i ** 2 <= X:
        if X % i == 0:
            X += 1
            i = 2
        else:
            i += 1
    print(X)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x = int(input())
primes = []
n = 2


def is_prime(num):
    for p in primes:
        if num % p == 0:
            return False
        if p * p > num:
            return True
    return True


while True:
    if is_prime(n):
        if n >= x:
            print(n)
            exit()
        else:
            primes.append(n)
    n += 1

Submission status: Accepted

Solution code:
X = int(input())

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

    
while prime(X)==0:
  X += 1
print(X)

Submission status: Accepted

Solution code:
X = int(input())
E = [1] * (2 * X)
for i, e in enumerate(E):
  if i < 2:
    continue
  if e < 1:
    continue
  for j in range(2 * i, 2 * X, i):
    E[j] = 0
for i, e in enumerate(E):
  if i < X:
    continue
  if e < 1:
    continue
  print(i)
  break

Submission status: Accepted

Solution code:
x=int(input())
def check(m):
  for i in range(2,int(m**.5)+1):
    if m%i==0:
      return 0
  return 1
while check(x)==0:
  x+=1
print(x)

Submission status: Accepted

Solution code:
X = int(input())

number = X
flag = 0

if number == 2:
  	print(number)
elif number%2 == 0:
    number += 1
else:
    pass
  
if number != 2:
    while(True):
        for i in range(2, number):
            if number%i == 0:
                number += 2
                break

            elif i == (number-1):
                flag = 1
                print(number)
                break

            else:
                pass

        if flag == 1:
            break

else:
  pass

Submission status: Accepted

Solution code:
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep = ' ', end = '\n'):
    print(*var, file=sys.stderr, end = end, sep = sep)

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

primes = []
M = 1000000
p = [1] * M
for i in range(2, M):
    if p[i]:
        for j in range(2*i, M, i):
            p[j] = 0
        primes.append(i)

x, = I()
for i in primes:
    if i >= x:
        print(i)
        break

Submission status: Accepted

Solution code:
X=int(input())
while 1:
    k=0
    i=2
    while i*i<=X:
         if X%i==0:
             k=1
             break
         i+=1
    if k==0:
        print(X)
        break
    X+=1

Submission status: Accepted

Solution code:
x = int(input())


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


def sosu(n):
    m = int(n ** (1 / 2) + 1)
    flag = True
    for i in range(2, m + 1):
        if n % i == 0:
            flag = False
    return flag


for i in range(10 ** 6):
    if sosu(x + i):
        print(x + i)
        exit()

Submission status: Accepted

Solution code:
def IsPrime(n):
    for i in range(2, n):
        if n % i == 0:
            return False
    return True

X = int(input())

while not IsPrime(X):
    X += 1
print(X)

Submission status: Accepted

Solution code:
x=int(input())

def prime(x):
  for i in range(2,x):
     if x%i ==0:
        return False
  return True
while not prime(x):
  x+=1
print(x)

Submission status: Accepted

Solution code:
x = int(input())

def sieve(n):
    is_prime = [True for _ in range(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]]
    return table

table = sieve(10**5 + 100)

l = 0
r = len(table) - 1

while l <= r:
    m = (l + r) // 2
    if table[m] >= x:
        r = m - 1
    else:
        l = m + 1

print(table[l])

Submission status: Accepted

Solution code:
import bisect

x = int(input())

def sieve(n):
    is_prime = [True for _ in range(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]]
    return table

table = sieve(10**5 + 100)

print(table[bisect.bisect_left(table, x)])

Submission status: Accepted

Solution code:
def eratosthenes(N):
    is_prime = {i: True for i in range(2, N+1)}
    primes = []
    for i in range(2, N+1):
        if is_prime[i]:
            primes.append(i)
            if i**2 <= N:
                for j in range(i**2, N+1, i):
                    is_prime[j] = False
    return primes


def main():
    X = int(input())
    primes = eratosthenes(100010)
    ans = 0
    for p in primes:
        if p >= X:
            print(p)
            break


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
LIMIT = 2 * 10**5
is_prime = [True] * LIMIT
is_prime[0] = False
is_prime[1] = False
primes = []
for i in range(LIMIT):
    if is_prime[i]:
        primes.append(i)
        for j in range(i*2, LIMIT, i):
            is_prime[j] = False

def solve(x):
    for i in range(len(primes)):
        if primes[i] >= x:
            return primes[i]
    return -1

x = int(input())
print(solve(x))

Submission status: Accepted

Solution code:
X = int(input())
if X == 2:
    print(2)
    exit()

N = 100010
flags = [True for i in range(N//2 + 1)]
flags[0] = False

lim = int(pow(N, 1/2))//2 + 1

for i in range(lim):
    if flags[i] is True:
        p = 2*i + 1
        for j in range(2*i*(i+1), N//2+1, p):
            flags[j] = False

for i in range(X//2, N//2 + 1):
    if flags[i] is True:
        print(2*i+1)
        break

Submission status: Accepted

Solution code:
x = int(input())

while True:
  i = 2
  prime = True
  
  while i * i < x:
    if x%i == 0:
      prime = False
      break
    i += 1
  if prime:
    print(x)
    break
  x += 1

Submission status: Accepted

Solution code:
N = int(input())
def prime(x):
  for i in range(2,N):
    if N%i == 0: #素数ではないか計算
      return False #素数ではない場合の戻り値
  return True #すべて計算した結果該当しない（素数）の戻り値

while True: #Nが素数であり続ける場合（Nが素数）
  if prime(N):
    print(N)
    break#Nが素数である場合終了
  N +=1

Submission status: Accepted

Solution code:
import bisect
import math
def get_sieve_of_eratosthenes(n):
    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]

n = int(input())
ans = list(get_sieve_of_eratosthenes(n*10))
index = bisect.bisect_left(ans,n)
print(ans[index])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdout
printn = lambda x: stdout.write(x)
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)


import math
# isprime, prime_division

def isprime(x):
    q = int(math.sqrt(x))  # int() rounds to zero
    for i in range(2,q+1):   # upto q
        if x%i == 0:
            return False
    return True

x = inn()
for i in range(x,10**5+10000):
    if isprime(i):
        print(i)
        exit()

Submission status: Accepted

Solution code:
def makePrime(n):
    i = 3
    while i*i < n:
        for p in P:
            if i%p == 0:
                i += 2
                break
        P.append(i)
        i += 2

X = int(input())
if X == 2:
    print(2)
    exit()
P = [2]
makePrime(X)
flg = 0
while 1:
    flg = 1
    for p in P:
        if X%p == 0:
            flg = 0
            X += 1
            break
    if flg:
        print(X)
        exit()

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
import sys
import bisect
import math
import itertools
import string
import queue
import copy
from itertools import permutations, combinations
from heapq import heappop, heappush
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
 
def inp(): # n=1
    return int(input())
def inpm(): # x=1,y=2
    return map(int,input().split())
def inpl(): # a=[1,2,3,4,5,...,n]
    return list(map(int, input().split()))
def inpls(): # a=['1','2','3',...,'n']
    return list(input().split())
def inplm(n): # x=[] 複数行
    return list(int(input()) for _ in range(n))
def inpll(n): # [[1,1,1,1],[2,2,2,2],[3,3,3,3]]
    return [list(map(int, input().split())) for _ in range(n)]

def div(x): #素因数配列
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div

def main():
    x = inp()
    for i in range(x,100004):
        if div(i)==[1,i]:
            print(i)
            return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
a=int(input())

def prime(n):
  if n <= 1:
    return False
  else:
    for i in range (2,n):
      if n%i == 0:
        return False
    return True
        
while prime(a)==False:
    a += 1

print(a)

Submission status: Accepted

Solution code:
X = int(input())

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

while is_prime(X)==False:
    X += 1

print(X)

Submission status: Accepted

Solution code:
import math

def isPrime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
    # ２ではない偶数は素数ではない
        return False

# nの半分まで計算する範囲を絞る
    m = math.floor(n / 2) + 1
    for p in range(3, m, 2): # 奇数だけ計算する
        if n % p == 0:
            return False
    return True
n=int(input())
while not isPrime(n):
    n+=1
print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def is_prime(x):
    if x <= 1:
        return False
    else:
        for i in range(2,x):
            if x % i == 0:
                return False
        return True

X = int(input())
while is_prime(X) == False:
    X += 1
print(X)

Submission status: Accepted

Solution code:
X = int(raw_input())

def check_prime(X):
    import math
    s = int(math.ceil(math.sqrt(X)))
    for a in range(2, s):
        if X % a == 0: 
            return False
    return True

while True:
    if check_prime(X): break
    X += 1

print X

Submission status: Accepted

Solution code:
import math

def prime(X):
    for i in range(2,math.ceil(math.sqrt(X))):
        if X % i == 0:
            return False
    return True

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from math import sqrt
x = int(input())

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

for i in range(x,10**6):
    if prime(i):
        print(i)
        exit()

Submission status: Accepted

Solution code:
import numpy as np
import sys

X = int(input())
def P(n):
  if n == 2:
    return True
  for p in range(2, int(np.sqrt(n))+1):
      if n % p == 0:
        return False
  return True

for i in range (X,110000):
  if P(i)==True:
    print(i)
    sys.exit()

Submission status: Accepted

Solution code:
n = 10**6
prime = {i for i in range(2,n)}
for i in range(2,n):
    if i in prime:
        for j in range(i*2,n,i):
            if j in prime:
                prime.remove(j)
                #エラトステネスの篩
prime=sorted(list(prime))
x=int(input())
for some in prime:
    if some>=x:
        print(some)
        break

Submission status: Accepted

Solution code:
X = int(input()) - 1

prime = False
while not prime:
    prime = True
    X += 1
    m = X
    i = 2
    while i <= m:
        if X % i == 0 and not X == i:
            prime = False
            break
        else:
            m = X // i
            i += 1
print(X)

Submission status: Accepted

Solution code:
def is_prime(X):
    flag = 1
    for i in range(2,int(X**0.5)+1):
        if X % i == 0:
            flag = -1
        if i == int(X**0.5) and flag == 1:
            print(X)
            exit()
X=int(input())
if X == 2:
    print(2)
    exit()
while(True):
    is_prime(X)
    X+=1

Submission status: Accepted

Solution code:
x = int(input())
a = round(x**0.5) + 1
import sys

if x == 2:
    print(2)
    sys.exit()
for i in range(x, 2*x+1):
    flag = 0
    for j in range(2,a+1):
        if i % j == 0:
            flag = 1 
            break
    if flag == 0:
        print(x)
        sys.exit()
    x += 1

Submission status: Accepted

Solution code:

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

    print(X)

def isPrime(X):
    ans = True
    for i in range(2, X//2):
        if(X % i == 0):
            ans = False
            break
    return ans

if __name__ == '__main__':
    X = int(input())
    FindPrime(X)

Submission status: Accepted

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

  if(X==2):
    print(X)
  elif(X%2>0):
    for i in range(50000):
      if(prime(X+i*2)==1):
        print(X+i*2)
        break
  else:
    for i in range(50000):
      if(prime(X+1+i*2)==1):
        print(X+1+i*2)
        break
        
def prime(A):
  m = int(A**0.5)
  for i in range(1,m,1):
    if(A%(i+1)==0):
      return 0
  return 1
    

if __name__=="__main__":
  main()

Submission status: Accepted

Solution code:
x = int(input())

def main():
    Bool = [1]*(2*x + 1)
    for i in range(2,2*x + 1):
        if Bool[i]:
            for j in range(2*i,2*x + 1,i):
                Bool[j] = 0
    for i in range(x,2*x + 1):
        if Bool[i]:
            print(i)
            return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
X=int(input())
while True:
    for i in range(2,int(math.sqrt(X))+1):
      if X%i==0:
        X+=1
        break
    else:
      print(X)
      break

Submission status: Accepted

Solution code:
import math
X = int(input())
while True:
  for n in range(2, int(math.sqrt(X)) + 1):
    if X % n == 0:
      X += 1
      break
  else:
    print(X)
    break

Submission status: Accepted

Solution code:
import math
x=int(input())
if x==2:
    print(x)
else:
    for i in range(x,200000):
        if x%2==0:
            x+=1
        else:
            buf=math.ceil(math.sqrt(x))
            a=0
            for j in range(3,buf+1,2):
                if x%j==0:
                    a+=1
                    break
                else:
                    continue
            if a!=0:
                x+=2
            else:
                print(x)
                break

Submission status: Accepted

Solution code:
from math import  sqrt
def isPrime(n):
    if (n == 0 or n == 1): return True
    else:
        
        for i in range(2,n):
            i = int(i)
            if (i*i > n): break
            if n % i == 0:
                return False
        return True

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

Submission status: Accepted

Solution code:
import math

N = int(input())


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


while True:
    if hoge(N):
        print(N)
        exit()
    N += 1

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


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

Submission status: Accepted

Solution code:
x=int(input())
def primeddx(x):
    for i in range(2,int(x**0.5)):
        if x%i==0:
            return False
    return True

while not primeddx(x):
    x+=1
print(x)

Submission status: Accepted

Solution code:
import numpy as np
x=int(input())
a = 0
b = 0
if x > 2:
    while b == 0:
        s = int(np.sqrt(x))
        for i in range(s):
            if x % (i+2) == 0:
                a = 1
                x += 1
                break
        if a == 0:
            b = 1
        else:
            a = 0
print(x)

Submission status: Accepted

Solution code:
x = int(input())
if x == 2:
    print(x)
    exit(0)
while True:
    
    for i in range(2,int(x**0.5) +3):
        if x %i == 0:
            break
    if i == int(x**0.5) +2:
        print(x)
        break
        
    

    
    
    
    
    
    x += 1

Submission status: Accepted

Solution code:
import math

def is_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 is_prime(N):
        print(N)
        exit()
    N += 1

Submission status: Accepted

Solution code:
x = int(input())

while True:
    flg = True
    for i in range(2, x//2+1):
        if x % i == 0.0:
            flg = False
            break
    if flg:
        print(x)
        break
    x += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=int(input())

def sd(x1): # 素数判別関数_1なら素数、0なら素数じゃない 引数は奇数
    rx1=x1**(1/2)//1
    j=3
    ans=1
    while rx1>=j:
        if x1%j==0:
            ans=0
            break
        else:
            ans=1
        j+=2
    return ans

if x%2==0 and x!=2:
    x+=1
while sd(x)==0:
    x+=2
print(x)

Submission status: Accepted

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

if __name__ == '__main__':
    n = int(input())
    while not is_prime(n):
        n += 1
    print(n)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

# 最小公倍数
def gcd(a, b):
	if a < b:
		a, b = b, a
	while a % b != 0:
		a, b = b, a % b
	return b
 
# 最大公約数 
def lcm(a, b):
	y = a*b / gcd(a, b)
	return int(y)

def primes_for(n):
  is_prime = [True] * (n + 1)
  is_prime[0] = False
  is_prime[1] = False
  for i in range(2, n + 1):
      for j in range(i * 2, n + 1, i):
          is_prime[j] = False
  return [i for i in range(n + 1) if is_prime[i]]

# O(√A)
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()

while isPrime(x) == False:
  x = x + 1
print(x)

Submission status: Accepted

Solution code:
import math
#----エラトステネスの篩--------
def get_primenumber(number):
    prime_list = []
    #2からnumberまでの数字をsearch_listに入れる
    search_list = list(range(2,number+1))
    while True:
      #search_listの先頭の値が√nの値を超えたら処理終了
      if search_list[0] > math.sqrt(number):
        #prime_listにsearch_listを結合
        prime_list.extend(search_list)
        break
      else:
        #search_listの先頭をprime_listに入れる
        head_num = search_list[0]
        prime_list.append(head_num)
        #search_listの先頭をpopする
        search_list.pop(0)
        #head_numの倍数を取り除く
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list

X = int(input())
PL=get_primenumber(100003)

Y = [p for p in PL if X<=p]
print(Y[0])

Submission status: Accepted

Solution code:
x=int(input())

def prime(n):
  if n==2:
    ans=True
  else:
    limit=int(n**(1/2)+1)
    ans=True
    for i in range(2,limit+1):
      if n%i==0:
        ans=False
        break
  return ans

expected=x-1
flag=True
while flag==True:
  expected+=1
  if prime(expected):
    flag=False
    ans=expected
    break
print(ans)

Submission status: Accepted

Solution code:
X = int(input())

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

while True:
        flag = 1
        for i in range(3, round(X**(1/2)), 2):
                if X % i == 0:
                        flag = 0
                        break
        if flag == 1:
                print(X)
                exit()
        X += 2

Submission status: Accepted

Solution code:
X=int(input())

import math
# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

pn=[]
for i in range(X, 10**5+4):
    if isPrime(i):
        pn.append(i)
print(min(pn))

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())

for i in range(n, 10000000):
  if (is_prime(i)):
    print(i)
    break

Submission status: Accepted

Solution code:
def isPrime(x):
    if x == 1:
        return False
    if x == 2:
        return True
    k = 3
    while k < x:
        if x % k == 0:
            return False
        k += 2
    return True
    
X = int(input())

while True:
    if isPrime(X):
        print(X)
        exit(0)
    X += 1

Submission status: Accepted

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

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

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

print(x)

Submission status: Accepted

Solution code:
X = int(input())

def is_prime(val):
    factor = 2
    ret = True
    while factor * factor <= val:
        if val % factor == 0:
            ret = False
            break
        factor += 1
    return ret

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

# simple, but more memory consumption of range
# for ans in range(X, X*X):
#     if is_prime(ans):
#         break
    
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import numpy as np
from functools import lru_cache
import time

def main(): 
    if True:
        A = int(input())
        #A = list(map(int, input().split()))
    else:
        pass

    while True:
        a = int(round(np.sqrt(A)))
        for i in range(2,a+1):
            if A % i == 0:
                break
        else:
            print(A)
            exit()
        A += 1



if __name__ =='__main__':
    main()

Submission status: Accepted

Solution code:
import math

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


while not is_prime(X):
    X += 1

print(X)

Submission status: Accepted

Solution code:
def isPrime(n):
    # 素数判定
    if n == 2:
        return True
    if n < 2 or n % 2 == 0:
        return False
    m = 3
    while m * m <= n:
        if n % m == 0:
            return False
        m += 2
    return True


def main():
    X = int(input())
    while True:
        if isPrime(X):
            print(X)
            break
        X += 1
    return


main()

Submission status: Accepted

Solution code:
def isPrime(n):
    # 素数判定
    if n < 2:
        return False
    for i in range(2, n + 1):
        if n < i ** 2:
            break
        if n % i == 0:
            return False
    return True


def main():
    X = int(input())
    while True:
        if isPrime(X):
            print(X)
            break
        X += 1
    return


main()

Submission status: Accepted

Solution code:
X = int(input())
def primeCheck(n):
    if n==2:
        return True
    for divisor in range(2, int(n**(0.5)+1)):
        if n % divisor == 0:
            return False
    return True
while(True):
    if primeCheck(X):
        print(X)
        break
    X += 1

Submission status: Accepted

Solution code:
#nの素数判定
def is_prime(n):
    if n == 1:
        return False
    for i in range(2,int(n**0.5)+1):
        if n % i == 0:
            return False
    return True

X=int(input())

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

print(X)

Submission status: Accepted

Solution code:
import math

P_lst=[2]
for i in range(1000):
  flag=0
  for j in P_lst:
    if (i+3)%j==0:
      flag=1

  if flag==0:
    P_lst.append(i+3)

X=int(input())

while X<=200000:
  if X==2:
    print(2)
    break
  flag=0
  x=math.sqrt(X)
  for k in P_lst:
    if X%k==0:
      break
    if x<k:
      flag=1
      break
  if flag==1:
    print(X)
    break
  X=X+1

Submission status: Accepted

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


N = int(input())

while True:
    if is_prime(N):
        print(N)
        exit()
    N += 1

Submission status: Accepted

Solution code:
def isPrime(X):
    if X == 0 or X == 1: return 0
    num = 2
    while num * num <= X:
        if X % num == 0: return 0
        num += 1
    return 1

X = int(input())

while isPrime(X) == 0: X += 1
print(X)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding:utf-8 -*-

from math import sqrt

def prime(ulim=10**5+10):
  cands = [2] + list(range(3, ulim, 2))
  primes = []
  while True:
    prime = cands.pop(0)
    primes.append(prime)
    if prime > sqrt(ulim):
      primes += cands
      break
    cands = [x for x in cands if x%prime != 0]
  return primes


if __name__=='__main__':
  x = int(input())
  for p in prime():
    if p >= x:
      print(p)
      break

Submission status: Accepted

Solution code:
n = int(input())

def is_prime(n):
    flag = True
    for i in range(2, n):
        if n % i == 0:
            flag = False
            break
    return flag

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

print(n)