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

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

def main():
    X = int(input())
    while not is_prime(X):
        X += 1
    print(X)
main()

Submission status: Accepted

Solution code:
x = int(input())
for i in range(x,100004):
    if all([i%p!=0 for p in range(2,i)]):
        print(i)
        break

Submission status: Accepted

Solution code:
X=int(input())
SUP=2*(10**5)
P=[True for i in range(2*(10**5))]
k=2
while k<SUP:
    if P[k]:
        for x in range(2*k,SUP,k):
            P[x]=False
    k+=1
ans=X
while not P[ans]:
    ans+=1
print(ans)

Submission status: Accepted

Solution code:
x = int(input())
def primes(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2,int(n**0.5) + 1):
        # 既にfalseになってたらスキップ
        if not is_prime[i]:
            continue
        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]]
prime_ls = primes(10**5 + 3)

r = len(prime_ls)- 1
l = -1
while r - l > 1:
    m = (r + l) // 2
    if prime_ls[m] >= x:
        r = m
    else:
        l = m
print(prime_ls[r])

Submission status: Accepted

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

#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

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

Submission status: Accepted

Solution code:
X = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
import math

X = int(input())
while True:
    check = True
    for i in range(2, math.floor(math.sqrt(X)) + 1):
        if X % i == 0:
            check = False
    if check:
        print(X)
        exit()
    else:
        X += 1

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

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

def main():
	x = II()
	ps = primes(2*10**5)
	for i,n in enumerate(ps[x:],x):
		if(n):
			print(i)
			exit()

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
x = int(input())
flag = False
for i in range(x, 10**10):
    for j in range(2, x):
        if i % j == 0:
            flag = True
    if not flag:
        print(i)
        exit()
    else:
        flag = False

Submission status: Accepted

Solution code:
def myAnswer(X:int) -> int:
   while True:
      for i in range(2,X):
         if(X % i==0):
            break
      else:
         return X
      X+=1

def modelAnswer():
   tmp=1
def main():
   X = int(input())
   print(myAnswer(X))

if __name__ == '__main__':
   main()

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, acos, atan, asin, log, log10
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 debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(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()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

x = INT()

NN = x * 2 + 100
primes = []
isprime = [True for _ in range(NN + 1)]
#エラトステネスの篩
for i in range(2, NN + 1):
    if not isprime[i]:
        continue
    primes.append(i)
    for j in range(i * 2, NN + 1, i):
        isprime[j] = False

for i in primes:
    if i >= x:
        print(i)
        exit()

Submission status: Accepted

Solution code:
X = int(input())
if(X%2 == 1 and X >= 6):
  for i in range(10000):
    j = 0
    while((X + 2*i) % (j+3) != 0 and (X + 2*i) > 2*(j+3)):
        j += 2
    if((X + 2*i) % (j+3) != 0):
        print(X + 2*i)
        break

elif(X == 2):
  print(2)

elif(X == 3):
  print(3)

elif(X == 4):
  print(5)

elif(X == 5):
  print(5)

else:
  for i in range(10000):
    j = 0
    while((X + 2*i + 1) % (j+3) != 0 and (X + 2*i + 1) > 2*(j+3)):
        j += 2
    if((X + 2*i + 1) % (j+3) != 0):
        print(X + 2*i + 1)
        break

Submission status: Accepted

Solution code:
# ABC149C
import math

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

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

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
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())
    while True:
        if is_prime(x)==True:
            print(x)
            break
        x+=1
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
def prime_list(n):
    primes = set(range(2, n+1))
    for i in range(2, int(n**0.5+1)):
        primes-=set(range(i*2, n+1, i))
    return list(primes)
def main():
    x=int(input())
    primes = prime_list(100010)
    for p in primes:
        if p >= x:
            print(p)
            break
if __name__=='__main__':
    main()

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())
for i in range(x, x + 10 ** 5):
    if is_prime(i):
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math


X = int(input())


def is_prime(x):
    n = math.floor(math.sqrt(x))
    ret = True
    for i in range(n, 1, -1):
        if x % i == 0:
            ret = False
            break
    return ret


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

Submission status: Accepted

Solution code:
x = int(input())

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

    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        

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from math import floor, ceil, sqrt
def isprime(n: int) -> bool:
    """
    Return n is a prime number or not
    """
    tmp = ceil(sqrt(n))
    for i in range(2, tmp + 1):
        if n % i:
            continue
        else:
            return False
    else:
        return True


x = int(input())
if x == 2:
    print(2)
    exit()
for i in range(x, 100004):
    if isprime(i):
        print(i)
        exit()

Submission status: Accepted

Solution code:
X = int(input())


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


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

Submission status: Accepted

Solution code:
def check_prime(m):
  prime_flag = 1
  counter = 2
  while counter **2 <= m:
    if not m%counter:
      prime_flag = 0
      break
    counter += 1
  return prime_flag


n = int(input())

for i in range(n, 10**6):
  if check_prime(i):
    print(i)
    break

Submission status: Accepted

Solution code:
import math

x = int(input())

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

Submission status: Accepted

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

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

a = X
if (X % 2 == 0) & (X > 2):
	a += 1
while 1:	
	if is_prime(a):
		print(a)
		break
	else:
		a += 2

Submission status: Accepted

Solution code:
X = int(input())

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

a = X
if (X % 2 == 0) & (X > 2):
	a += 1
while 1:	
	if is_prime(a):
		print(a)
		break
	else:
		a += 2

Submission status: Accepted

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

def prime(x):
    if x==2:
        return 2
    if x==3:
        return 3
    if x%2==0:
        x+=1
    while True:
        boo=False
        for i in range(2,x):
            if x%i==0:
                boo = True
                break
        if boo==False:
            return x
        else:
            x+=2
        

print(prime(x))

Submission status: Accepted

Solution code:
from math import sqrt
x = int(input())
while x:
    cnt = 0
    for i in range(2, int(sqrt(x)) + 1):
        if x % i != 0:
            cnt += 1
    if cnt == int(sqrt(x)) - 1:
        print(x)
        exit()
    else:
        x += 1

Submission status: Accepted

Solution code:
x = int(input())

# 約数のリストを作る
# sortはされてないのできをつけよう
def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if(n%i == 0):
            divisors.append(i)
            if(i!= n//i):
                divisors.append(n//i)

    return  divisors

while(True):
    tmp = make_divisors(x)
    if(len(tmp) == 2):
        break
    x += 1

print(x)

Submission status: Accepted

Solution code:
import math
x = int(input())
while True:
    ok = True
    for j in range(2, int(math.sqrt(x))+1):
        if x % j == 0:
            ok = False
    if ok:
        print(x)
        exit() 
    x += 1

Submission status: Accepted

Solution code:
def ifPrine(n):
    if n <= 1:
        return True
    elif n == 2 or n == 3:
        return False
    else:
        i = 2
        while i*i <= n:
            if n % i == 0:
                return True
            else:
                i += 1
    return False

x = int(input())
q = 0
while q < 100000:
    if ifPrine(x+q) == False:
        print(x+q)
        break
    else:
        q += 1

Submission status: Accepted

Solution code:
x = int(input())
pr = [2]
if x == 2:
    print(2)
else:
    for i in range(3,100009,2):
        fr = 0
        for j in pr:
            if i % j == 0:
                fr += 1
                break
        if fr == 0:
            if i >= x:
                print(i)
                break
            pr.append(i)

Submission status: Accepted

Solution code:
X=int(input())

flg = True
while flg:
    for x in range(2,X):
        if X%x == 0:
            flg = False
    if flg == False:
        X+=1
        flg = True
    else:
        print(X)
        exit()

Submission status: Accepted

Solution code:
x = int(input())

def is_prime(x):
    while True:
        for i in range(2, x):
            if x % i == 0:
                return False
        return True

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

Submission status: Accepted

Solution code:
import numpy as np

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

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

    return True

x = int(input())

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

Submission status: Accepted

Solution code:
import math
def isPrime(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(10**5):
  if isPrime(x+i):
    print(x+i)
    break

Submission status: Accepted

Solution code:
import math

X=int(input())

def judge(x):
    judge=True
    h=int(math.sqrt(x))
    for i in range(2,h+1):
        r=x%i
        if r==0:
            judge=False
            break
    
    return judge

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

Submission status: Accepted

Solution code:
n = int(input())

import math
def prime(n):
  a = math.ceil(math.sqrt(n))
  for i in range(2,a):
    if n%i==0: return 1
  return 0

while (1):
  if prime(n)==0: 
    print(n)
    exit()
  n+=1

Submission status: Accepted

Solution code:
import math

def is_prime(x):
    if x < 2: return False  # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True  # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False  # 2,3,5の倍数は合成数
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False
        prime += step
        step = 6 - step
    return True

def main():
    X = int(input())
    while 1:
        if is_prime(X):
            print(X)
            break
        X += 1


if __name__ == '__main__':
    main()

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

for i in range(X,100000000):
  if is_prime(i) == True:
    print(i)
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X=int(input())
ans=0
for i in range(X,10**8):
    f=0
    for n in range(2,i):
        if i%n==0:
            f+=1
            break
    if f==0:
        ans=i
        break
print(ans)

Submission status: Accepted

Solution code:
x = int(input())

import random


def is_prime3(q, k=50):
    q = abs(q)
    # 計算するまでもなく判定できるものははじく
    if q == 2: return True
    if q < 2 or q & 1 == 0: return False

    # n-1=2^s*dとし（但しaは整数、dは奇数)、dを求める
    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    # 判定をk回繰り返す
    for i in range(k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        # [0,s-1]の範囲すべてをチェック
        while t != q - 1 and y != 1 and y != q - 1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q - 1 and t & 1 == 0:
            return False
    return True


while True:
    if is_prime3(x):
        print(x)
        exit()
    x += 1

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

import math
from bisect import bisect_left

def eratosthenes(limit):
    limit += 10 ** 3
    A = [i for i in range(2, limit + 1)]
    P = []

    for i in range(limit):
        prime = min(A)

        if prime > math.sqrt(limit):
            break

        P.append(prime)
        for j in range(limit):
            if j >= len(A):
                break
            if A[j] % prime == 0:
                A.pop(j)
                continue

    for a in A:
        P.append(a)

    return P


x = int(readline())
ans = eratosthenes(x)
print(ans[bisect_left(ans, x)])

Submission status: Accepted

Solution code:
X = int(input())
while True:
  L = []
  for i in range(1, int(X ** 0.5) + 1):
    if X % i == 0:
      L.append(i)
      if i != X // i:
        L.append(X // i)
  if L == [1, X]:
    print(X)
    exit()
  else:
    X += 1

Submission status: Accepted

Solution code:
x = int(input())
flag = 0

for i in range(x, x + 1000):
    for j in range(2, x):
        if i%j == 0:
            flag = 1
            break
    if flag == 0:
        print(i)
        exit()
    else:
        flag = 0

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = int(input())

while True:
    flg=True
    for i in range(2, X):
        if X%i!=0:
            continue
        flg=False
        break
    if flg:
        print(X)
        break
    else:
        X+=1
        continue

Submission status: Accepted

Solution code:
import math

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

x=int(input())

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

print(x)

Submission status: Accepted

Solution code:
def isPrime(x):
    if x < 2:
        return False
    for i in range(2, int(pow(x, 0.5)+1)):
        if x%i==0:
            return False
    return True

X = int(input())

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import math
x = int(input())
n = 10 ** 10
for i in range(x, n):
    for k in range(2, x):
        if i % k == 0:
            break
    else:
        print(i)
        exit()

Submission status: Accepted

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

while flag ==0:
	if X==2:
		X+=1
		break
	for i in range(X-2):
		if X%(i+2)==0:
			break
		if i+3==X:
			flag = 1
			break
	X +=1

print(X-1)

Submission status: Accepted

Solution code:
x = int(input())
for i in range(x, 100003 + 1):
    for j in range(2, i):
        if i % j == 0:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
x = int(input())
p = [True] * 100004
p[0] = False
p[1] = False
for i in range(int(100003 ** 0.5)):
    if p[i] == False:
        continue
    for j in range(2, 100003 // i + 1):
        p[i * j] = False
for i in range(x, 100004):
    if p[i] == True:
        print(i)
        break

Submission status: Accepted

Solution code:
X = int(input())

def isPrime(x):
    if x <= 1: 
        return False

    for i in range (2, int(x**(1/2)) + 1):
        if x%i == 0:
            return False

    return True

p = X

while isPrime(p) != True:
    p += 1

print(p)

Submission status: Accepted

Solution code:
import numpy as np
import math
x = int(input())
prime = True
while prime:
    flag = 0
    for j in range(2,math.ceil(np.sqrt(x))):
        if x%j == 0:
            flag = 1
            break
    if flag ==0:
        prime = False
        
    else:
        x+=1
            
print(x)

Submission status: Accepted

Solution code:
import math

X = int(input())

# 素数判定関数
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

# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

l = callIsPrime(100004)

for i in range(len(l)):
    if l[i] >= X:
        print(l[i])
        break

Submission status: Accepted

Solution code:

def prime(n):
  cnt = 0
  for i in range(1,n):
    if n % i == 0:
        cnt += 1
  if cnt == 1:
    return n
  else:
    return -1

x = int(input())
for i in range(x,2*10**5):
  if prime(i) != -1:
    print(prime(i))
    exit()

Submission status: Accepted

Solution code:
X = int(input())
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
for i in range(2,100004):
    if i >= X and is_prime(i) == True:
        print(i)
        break

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

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

Submission status: Accepted

Solution code:
import math
import sys

def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0
    
    while True:
        prime = min(A)
        
        if prime > math.sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

X = int(input())
for i in eratosthenes(100003):
    if i >= X:
        print(i)
        sys.exit()

Submission status: Accepted

Solution code:
X=int(input())
while 1:
    Judge=0
    for i in range(2, X):
        if X%i==0:
            Judge=1
            break
    
    if Judge:
        X+=1
    else:
        break

print(X)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=int(input())
count=0

n=1
while True:
	n+=1
	ans=True
	for i in range(2,int(x**0.5)):
		if n%i==0:
			ans=False
			break
	if ans and n>=x:
		print(n)
		break

Submission status: Accepted

Solution code:
# 初期入力
X = int(input())

#素数リスト
n = X # X以下の素数
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

n = X *2# Xの2倍までの素数
primes_bai = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes_bai.difference_update(range(i*2, n+1, i))
primes_bai=list(primes_bai)

# 2倍までの素数からX以下の素数を引く
X_koetasaisyo = set(primes_bai) - set(primes) 
X_koetasaisyo_list = list(X_koetasaisyo)
X_koetasaisyo_list.append(primes[-1])
X_koetasaisyo_list.sort()

if X == X_koetasaisyo_list[0]: # Xと等しかったらそれが答え
    print(X_koetasaisyo_list[0])
else:
    print(X_koetasaisyo_list[1])

Submission status: Accepted

Solution code:
import bisect

n = 10**5+100
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes=list(primes)

x=int(input())
y=bisect.bisect_left(primes,x)
print(primes[y])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x = int(input())

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

if x != 2:
    x = x + 1 - x % 2
while not judge_prime(x):
    x += 2
print(x)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math
n=int(input())
if n ==2:
  print(n)
  exit()

w=math.ceil(math.sqrt(n))
for k in range(n,1000000):
  f=False
  for i in range(2,w+1):
    if k%i==0:
      f=True
      break
  if not f:
    print(k)
    exit()

Submission status: Accepted

Solution code:
def primes(n):
    i = 1
    p = [2]
    while i+2 <= n:
        flag = True
        i += 2
        for j in range(3, int(i**(1/2))+1, 2):
            if i % j == 0:
                flag = False
                break
        if flag:
            p.append(i)
    return p
            
n = int(input())
p = primes(10**5+10)
print([i for i in p if i >= n][0])

Submission status: Accepted

Solution code:
import bisect


def sieve(n):
    is_prime = [True for _ in range(n+1)]
    is_prime[0] = is_prime[1] = False

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

    table = [i for i in range(1, n + 1) if is_prime[i]]
    return is_prime, table


_, prime_table = sieve(10**5 + 4)

x = int(input())
print(prime_table[bisect.bisect_left(prime_table, x)])

Submission status: Accepted

Solution code:
x=int(input())

def eratosthenes(n):
    prime_check=[True for _ in range(100010)]
    prime_check[0]=False
    prime_check[1]=False
    for i in range(2,n+1):
        j=2
        while(i*j<=n):
            prime_check[i*j]=False
            j+=1
        if(i*j<100010):
            prime_check[i*j]=False
    return prime_check


p=eratosthenes(x)
i=x
while(True):
    if(p[i]):
        print(i)
        break
    else:
        i+=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())
ans = float('inf')

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math
import sys
input = sys.stdin.readline

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):
            print(i)
            break

if __name__ == '__main__': main()

Submission status: Accepted

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

a = int(input())
while True:
    if isPrime(a):
        print(a)
        break
    a += 1

Submission status: Accepted

Solution code:
from collections import deque
from collections import Counter
from itertools import product, permutations,combinations
from operator import itemgetter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right, bisect
#pypyではscipy, numpyは使えない
#from scipy.sparse.csgraph import shortest_path, floyd_warshall, dijkstra, bellman_ford, johnson, minimum_spanning_tree
#from scipy.sparse import csr_matrix, coo_matrix, lil_matrix
#import numpy as np
from fractions import gcd
from math import ceil,floor, sqrt, cos, sin, pi, factorial
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10**8)
INF = float('inf')
from datetime import datetime as dt

def main():
  x = int(input())
  prime = [True]*(x*2)
  prime[0] = False
  prime[1] = False
  for i in range(2, x):
    if prime[i]==True:
      baisu = i + i
      while baisu<2*x:
        prime[baisu]=False
        baisu += i
  for i in range(x,2*x):
    if prime[i]==True:
      print(i)
      break
  
  
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import math
X = int(input())
for i in range(X, 1000000):
  goseisu = False
  for j in range(2, X):
    if i % j == 0:
      goseisu = True
      break
  if not goseisu:
    print(i)
    exit()

Submission status: Accepted

Solution code:
import math
X = int(input())
 
if X == 2:
  print(2)
  exit()
  
hajime = X
 
#if hajime % 2 == 0:
#  hajime += 1
#checkMax = math.ceil(math.sqrt(hajime))
for i in range(hajime, 1000000):
  goseisu = False
  for j in range(2, hajime):
    if i % j == 0:
      goseisu = True
      break
  if not goseisu:
    print(i)
    exit()

Submission status: Accepted

Solution code:
import math
X = int(input())
 
if X == 2:
  print(2)
  exit()
  
hajime = X
 
if hajime % 2 == 0:
  hajime += 1
checkMax = math.ceil(math.sqrt(hajime))
for i in range(hajime, 1000000):
  goseisu = False
  for j in range(2, checkMax + 1):
    if i % j == 0:
      goseisu = True
      break
  if not goseisu:
    print(i)
    exit()

Submission status: Accepted

Solution code:
import math
X = int(input())
 
if X == 2:
  print(2)
  exit()
  
hajime = X
 
if hajime % 2 == 0:
  hajime += 1
checkMax = math.ceil(math.sqrt(hajime))
for i in range(hajime, 1000000, 2):
  goseisu = False
  for j in range(2, checkMax + 1):
    if i % j == 0:
      goseisu = True
      break
  if not goseisu:
    print(i)
    exit()

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):
        break
    x += 1

print(x)