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 sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

L = [1 for i in range(100010)]
L[0] = 0
L[1] = 0
plist = []
for i in range(100010):
	if L[i] == 1:
		plist.append(i)
		c = 2
		while True:
			if i * c <= 100009:
				L[i * c] = 0
				c += 1
			else:
				break

#処理内容
def main():
	X = int(input())
	for i in plist:
		if X <= i:
			print(i)
			break

if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
def sosuu(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n+1):
        j = i + i
        while j <= n:
            is_prime[j] = False
            j += i
    return [p for p in range(n+1) if is_prime[p]]

primes = sosuu(300000)
import bisect
x = int(input())

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

Submission status: Accepted

Solution code:
X = int(input())

def prime(x,number):
    return x % number 


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

else:
    ## X is prime, or not.
    for number in range(2, X+1):
        if prime(X,number) == 0 and number != X:
            break
        elif prime(X,number) == 0 and number == X:
            print(X)
            quit()

    ## find prime number larger than X
    flag = True
    while flag:
        X = X + 1
        for number in range(2, X+1):
            if prime(X,number) == 0 and number != X:
                break
            elif prime(X,number) == 0 and number == X:
                flag = False
                print(X)

Submission status: Accepted

Solution code:
def nextprime(x):
    for i in range(2, x):
        if x % i == 0:
            return nextprime(x+1)
    return x


x = int(input())

if x == 2:
    print("2")
else:
    print(nextprime(x))

Submission status: Accepted

Solution code:
def nextprime(x):
    if pow(2, x-1, x) != 1:
        return nextprime(x+1)
    for i in range(2, x):
        if x % i == 0:
            return nextprime(x+1)
    return x


x = int(input())

if x == 2:
    print("2")
else:
    print(nextprime(x))

Submission status: Accepted

Solution code:
import numpy as np
from bisect import bisect_left


def primes():
    p = []
    c = np.ones(10**5 + 10)
    c[0] = c[1] = 0
    for i, f in enumerate(c):
        if f:
            p.append(i)
            c[2 * i:10**5 + 10:i] = 0
    return p


def solve(string):
    x = int(string)
    ps = primes()
    return str(ps[bisect_left(ps, x)])


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Accepted

Solution code:
X = int(raw_input())
con = 0
for i in range(X,X+100):
  #print i
  for j in range (2,i):
    if i%j==0:
      con = con + 1
  if con == 0:
    print i
    break
  else:
    con = 0
    continue

Submission status: Accepted

Solution code:
import math

x = int(input())

def is_prime(n: int) -> bool:
    if n == 1: return False

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

    return True

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

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())
i = X
while True:
    if isPrime(i):
        break
    i+=1
print(i)

Submission status: Accepted

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

def isPrime(x):
	ans = 0
	if x==1:
		ans = 1
	else:
		for i in range(2,x):
			if x%i==0:
				ans = 1
				break;
	return ans

x = int(input())

while 1:
	if isPrime(x)==0:
		break
	if x%10==1 or x%10==3 or x%10==7:
		x += 2
	else:
		x += 1

print(x)

Submission status: Accepted

Solution code:
import math

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

  return True

x = int(input())
while is_prime(x) is False:
  x += 1

print(x)

Submission status: Accepted

Solution code:
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    x = int(input().rstrip('\n'))
    for i in range(x, 10 ** 10):
        b = True
        for j in range(2, int(i ** 0.5) + 1):
            if i % j == 0:
                b = False
                break
        if b:
            print(i)
            exit()


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

n = int(input())
primes = prime_flags(1000000)
for i in range(n, 1000000):
    if primes[i]:
        print(i)
        exit()

Submission status: Accepted

Solution code:
x = int(input())
is_prime = False

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

Submission status: Accepted

Solution code:
x = input()

def is_sosu(num):
  st = 2
  while True:
    if num % st == 0:
      break
    st += 1
  if st == num:
    print(num)
    return
  is_sosu(num+1)

is_sosu(int(x))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import floor

tmp = int(input())
while True:
    for i in range(2, floor(tmp ** (1 / 2))):
        if tmp % i == 0:
            tmp += 1
            break
    else:
        print(tmp)
        break

Submission status: Accepted

Solution code:
from math import sqrt

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

x = int(input())
while next_prime(x):
      x = x + 1

print(x)

Submission status: Accepted

Solution code:
def prime(x):
  p = {}
  cnt = 2
  Flag = True
  while Flag:
    last = math.ceil(x ** 0.5) 
    if cnt > last:
      break
    for i in range(cnt, last + 1):
      if x % i == 0:
        x //= i
        p[i] = 1
        cnt = i + 2
        while x % i == 0:
          x //= i
          p[i] += 1
        cnt = i + 1
        break
      if i == last:
        Flag = False
  if x != 1:
    p[x] = 1
  if len(p) == 1:
    for i in p:
      if p[i] == 1:
        return True
      else:
        return False
  else:
    return False

X = int(input())
import math

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

Submission status: Accepted

Solution code:
X = int(input())

while 1:
	ok = 1
	for i in range(2, X):
		if X % i == 0:
			ok = 0
			break

	if ok:
		print(X)
		exit()
	X += 1

Submission status: Accepted

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

print(x+i)

Submission status: Accepted

Solution code:
X = int(input())

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

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

X = X - 1
print(X)

Submission status: Accepted

Solution code:
MAX_X = 10 ** 5
buffer = 10 ** 3
prime_flags = [1 for _ in range(MAX_X + buffer)]

for i in range(2, MAX_X + buffer):
  num = i
  if prime_flags[num] == 0:
    continue
  while num + i < len(prime_flags):
    num += i
    prime_flags[num] = 0

X = int(input().strip())
for i, flag in enumerate(prime_flags[X:]):
  if flag == 1:
    print(X + i)
    break

Submission status: Accepted

Solution code:
a = int(input())
for i in range(a,10**7):
  result=[x for x in range(1,i+1) if i%x==0]
  if len(result)==2:
    print(i)
    break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = int(input())

r = X

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X=int(input())

ans=X
f=True

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

Submission status: Accepted

Solution code:
X=int(input())

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

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

Submission status: Accepted

Solution code:
A = int(input())
if A == 2:
    print(2)
    exit()
sosu = [2] #素数が入る
sosu_2 = [4] #素数の2乗の数が入る
sosu_2_index = 1
for num in range(3, 100010, 2):
    if  num > sosu_2[sosu_2_index-1]:
        sosu_2_index += 1
    flag =  True
    for i in range(1,sosu_2_index):
        if num % sosu[i] == 0:
            flag = False
            break
    if flag:
        sosu.append(num)
        if num >= A:
            print(num)
            exit()
        sosu_2.append(num**2)

Submission status: Accepted

Solution code:
x = int(input())
flg = 0
while flg == 0:
    lo_flg = 1
    mx  = int(x**0.5)
    for i in range(2, mx+1):
        if x % i == 0:
            lo_flg = 0
            break
    flg = lo_flg
    if flg == 0:
        x+=1
print(x)

Submission status: Accepted

Solution code:
def com(_x):
    _flg = 1
    mx  = int(_x**0.5)
    for i in range(2, mx+1):
        if _x % i == 0:
            _flg = 0
            break
    return _flg


x = int(input())
flg = 0
while flg == 0:
    #print("a")
    flg = com(x)
    if flg == 0:
        x+=1
print(x)

Submission status: Accepted

Solution code:
X = int(input())


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


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

Submission status: Accepted

Solution code:
def com(_x):
    _flg = 1
    mx  = int(_x**0.5)
    for i in range(2, mx+1):
        if _x % i == 0:
            _flg = 0
            break
    return _flg


def main():
    x = int(input())
    flg = 0
    while flg == 0:
        #print("a")
        flg = com(x)
        if flg == 0:
            x+=1
    print(x)



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
def is_prime(n):
    if n==2:
        return True
    if n%2==0:
        return False
    for i in range(3,int(math.sqrt(n))+1,2):
        if n%i==0:
            return False
    return True
if __name__=="__main__":
    x=input()
    x=int(x)
    res=x
    while True:
        if is_prime(res):
            print(res)
            break
        res+=1

Submission status: Accepted

Solution code:
start = int(input())
# 検討している数字の範囲は10**5だが、見つけたい素数はその範囲を越えている可能性がある
# 10**5を越える最初の素数は100003で、rangeの特性上10**5+4とした
stop = 10**5 + 4

# if, elseは必ずしも同じforループ内で動かなくてもよい
# もし普通にif, elseを書くと、1つ処理を行ってfalseだとすぐelseになる
# でも今回は、1つの処理ではなく、まとまった処理を行った上で全てfalseの時を知りたいので、forの階層がずれる

for i in range(start, stop, 1):
    for j in range(2, round(i**0.5)+1, 1):
        if i % j == 0:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
x=int(input())

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

for i in range(x,x+1234567890):
	if isPrime(i):
		print(i)
		exit()

Submission status: Accepted

Solution code:
import sys
x = input()
x = int(x)
pn = []
k = x
while True:
    cnt = 0
    for j in range(int(x/2)):
        j += 1
        if cnt >= 2:
            break
        if k % j == 0:
            cnt += 1
    if cnt < 2:
        ans = k
        break
    k += 1
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

prims = list()

prims.append(2)

base = int(input())

def _is_prim(n):
  global prims
  for p in prims:
    if n == p:
      return True
    elif n % p == 0:
      return False
  
  return True

# 入力値の平方根までの素数を作る
rt = int(math.sqrt(base))
for n in range(rt):
  if n < 2:
    continue
  elif n % 2 == 0:
    continue
  elif _is_prim(n):
    prims.append(n)

# 作った素数値で。。。
while not _is_prim(base):
  base += 1

print(base)

Submission status: Accepted

Solution code:
import numpy as np

X = int(input())

def get_primes(n):
    numbers = set(range(n, 1, -1))
    primes = []
    while numbers:
        p = numbers.pop()
        primes.append(p)
        numbers.difference_update(set(range(p*2, n+1, p)))
    return primes

primes = sorted(get_primes(110000))

print(primes[list(np.array(primes) >= X).index(True)])

Submission status: Accepted

Solution code:
import sys
import math

sys.setrecursionlimit(10**5)

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

x = int(input())
target = x
do = True
while do:
    if is_prime_num(target):
        print(target)
        do = False
    target += 1

Submission status: Accepted

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

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

    return True

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

Submission status: Accepted

Solution code:
x = int(input())
N = 1000000
def solve():
    primes = [False] * N
    for i in range(2, N):
        if primes[i]:
            continue
        for j in range(i*i, N, i):
            primes[j] = True

        if i >= x:
            print(i)
            return

solve()

Submission status: Accepted

Solution code:
import numpy as np
a = np.array([2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367])
candidate = int(input())


while True:
  if ((candidate / a[a<candidate]) % 1 == 0).any():
    candidate += 1
  else:
    break
print(candidate)

Submission status: Accepted

Solution code:

import math

number_to_check = int(input())

def if_prime(number):
    for i in range(2, int(math.sqrt(number) + 1)):
        if number%i == 0:
            return 0
    
    return 1

def check_next_prime(X):
    while(True):
        if if_prime(X):
            break 
        else:
            X += 1
            continue
    print(X)


check_next_prime(number_to_check)

Submission status: Accepted

Solution code:
x = int(input())

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

Submission status: Accepted

Solution code:
X = int(input())

memo = [None]*(2*X)

for i,v in enumerate(memo):
    if i < 2:
        continue
    if v is None:
        memo[i] = True
        for j in range(i*2, 2*X, i):
            memo[j] = False

print(next(i+X for i,v in enumerate(memo[X:]) if v))

Submission status: Accepted

Solution code:
X = int(input())

while True:
    
    flag = 0
    
    for i in range(2, X): #2からX-1までのループ
        if X % i == 0: #対象はXという数
            flag = 1
            break
    if flag == 1:
        X += 1
        continue
    break
    
print(X)

Submission status: Accepted

Solution code:
import numpy as np

def check_prime(t):
    for p in range(2, int(np.sqrt(t))+1):
        if(t % p == 0):
            return False
    return True

X = int(input())

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

Submission status: Accepted

Solution code:
import math
import bisect
x = int(input())
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]
N = primes(1000004)
z = bisect.bisect_left(N, x)
print(N[z])

Submission status: Accepted

Solution code:
def is_prime(num):
    for i in range(2, num):
        if num % i == 0:
            return False

    return True

def main():
    x = int(input())
    while True:
        if is_prime(x):
            print(x)
            break

        x += 1

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math


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

def next_prime(x):
    i = x
    while True:
        if is_prime(i):
            return i
        i += 1

x = int(input())
print(next_prime(x))

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):
    print(x)
    exit()
  x += 1

Submission status: Accepted

Solution code:
n =10**5+4
p = [False] * 2 + [True] * (n-2)
for i in range(2,n):
    if p[i]:
        for j in range(i*2,n,i):
            p[j] = False
x=int(input())
while p[x]==False:
    x+=1
print(x)

Submission status: Accepted

Solution code:
a=int(input())

for i in range(a,10**6):
  isprime=True
  for j in range(2,i):
    if i%j==0:
      isprime=False
      break
  if isprime==True:
    print(i)
    exit()

Submission status: Accepted

Solution code:
MAX_PRIME = 10**6
is_prime = [1] * MAX_PRIME
primes = []
is_prime[0] = 0
is_prime[1] = 0
for i in range(MAX_PRIME):
    if is_prime[i]:
        primes.append(i)
        for j in range(2, ((MAX_PRIME-1)//i) + 1):
            is_prime[i*j] = 0

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc149/tasks/abc149_c

X = int(input())

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

i = X
# ループする
while i < 1000000:
    if isPrime(i):
        print(i)
        break
    else:
        i = i + 1

Submission status: Accepted

Solution code:
def is_prime(n):
    for i in range(2, n + 1):
        if i * i > n:
            break
        if n % i == 0:
            return False
    return n != 1


import sys
input = sys.stdin.readline().rstrip
X = int(input())

if X%2 == 0:
    if X == 2:
        print(2)
    else:
        X += 1
        for num in range(X, 10**6, 2):
            if is_prime(num):
                print(num)
                break
else:
    for num in range(X, 10**6, 2):
        if is_prime(num):
            print(num)
            break

Submission status: Accepted

Solution code:
def main():
  N = int(input())
  
  print(search(N))
 
def search(x):
  
  ints = list(range(2,x))
  
  # 順に確認する
  for i in ints:
    if x%i==0:
      return search(x+1)
    elif x < i**2:
      break
    
  return x

main()

Submission status: Accepted

Solution code:
def seive(num,n):
    li=[True]*(n+1)
    x=2
    li[0]=False
    li[1]=False
    while x*x<n:
        if li[x]:
            for i in range(x*x,len(li),x):
                
                li[i]=False
                
        x+=1
        
        
    for i in range(num,len(li)):
        if li[i]:
            return i
num=int(input())
print(seive(num,1000000))

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
x=int(input())
while 1:
    flag=0
    for i in range(2,int(x**(1/2))):
        if x%i==0:
            flag=1
            break
    if flag==0:
        break
    x+=1
print(x)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
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):
        print(X)
        exit()
    X += 1

Submission status: Accepted

Solution code:
import math

def is_prime(x):
  if x <= 1:
    return False
  max_judge = math.sqrt(x)
  count = 2
  while(count < max_judge):
    if x % count == 0:
      return False
    count+=1
  return True
 
x = int(input())
 
judge_prime = False

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

print(x)

Submission status: Accepted

Solution code:
# ABC149C
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文じゃなくてwhileを使う方が良い
"""
for i in range(X, 2 * 10 ** 7):
    if is_prime(i):
        print(i)
        exit()
"""

while 1:
    if is_prime(X):
        print(X)
        exit()
    X += 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())
for i in range(X, 2 * 10 ** 7):
    if is_prime(i):
        print(i)
        exit()

Submission status: Accepted

Solution code:
from itertools import takewhile, count

def is_prime(x):
    if x == 1:
        return False
    for z in takewhile(lambda y: (y * y) <= x, count(2)):
        if (x % z) == 0:
            return False
    return True

def solve(x):
    while not is_prime(x):
        x += 1
    return x

print(solve(int(input())))

Submission status: Accepted

Solution code:
from math import sqrt

x = int(input())
if x == 2:
  print(2)
else:
  if x % 2 == 0:
    x += 1
  while True:
    flag = True
    for mod in range(3, int(sqrt(x))+1, 2):
      if x % mod == 0:
        flag = False
        break
    if flag:
      print(x)
      break
    else:
      x += 2

Submission status: Accepted

Solution code:
x = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
# INPUT
input = list(map(float, input().split()))

q = int(input[0])

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 True:
  if is_prime(q):
    print(q)
    sys.exit()
  q = q + 1

Submission status: Accepted

Solution code:
import math

x = int(input())

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

    if flag:
        print(x)
        exit()
    else:
        x += 1

Submission status: Accepted

Solution code:
def prime(x):
    flag = True
    n = 1
    while(n**2 <=x):
        n += 1
        q,r = divmod(x,n)
        if r==0:
            flag = False
            break
    return flag

def find(x):
    c = x
    while(prime(c)==False):
        c +=2
    return c


x = int(input())
if x==2:
    print(x)
elif x%2==0:
    print(find(x+1))
else:
    print(find(x))

Submission status: Accepted

Solution code:
x=int(input())

n=2*10**5
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

for i in range(x,n):
  if is_prime[i]:
    print(i)
    break
  else:
    continue

Submission status: Accepted

Solution code:
m = int(input())
if m <= 2 :
  print('2')
else:
  n = 2*10**5
  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)

  for i in range(len(primes)-1):
    if primes[i] < m and m <= primes[i+1]:
      print(primes[i+1])

Submission status: Accepted

Solution code:
m = int(input())
if m <= 2 :
  print('2')
else:
  n = 10**6
  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)

  for i in range(len(primes)-1):
    if primes[i] < m and m <= primes[i+1]:
      print(primes[i+1])

Submission status: Accepted

Solution code:
x = int(input())

for i in range(x, 150000):
    isPrime = True
    for j in range(2, x):
        if i%j == 0:
            isPrime = False
            break
    if isPrime == True:
        print(i)
        exit()

Submission status: Accepted

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

num = 3
ps = [2]
while 1:
  flag = True
  for p in ps:
    if num%p == 0:
      flag = False
      break
  if flag:
    ps.append(num)
    if num>=X:
      print(num)
      exit()
  num += 2

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-


class Prime(object):
    '''Represents a snippet for prime numbers.
    '''

    def __init__(self, number):
        self.number = number
        self._values = []

    def is_included(self) -> bool:
        '''Determine whether it is a prime number.
        Args:
            number: Int of number (greater than 0).
        Returns:
            True if the input number was prime.
            False if the input number was not prime.
        See:
            https://qiita.com/srtk86/items/874639e361917e5016d4
            https://docs.python.org/ja/3/library/2to3.html?highlight=isinstance#2to3fixer-isinstance
        '''

        from math import sqrt

        if (self.number <= 1) or (isinstance(self.number, float)):
            return False

        for i in range(2, int(sqrt(self.number)) + 1):
            if self.number % i == 0:
                return False

        return True

    def generate(self) -> list:
        '''Generate a list of prime numbers using sieve of Eratosthenes.
        Returns:
            A list of prime numbers that is eqaul to or less than the input
            number.
        Landau notation: O(n log log n)
        See:
            https://beta.atcoder.jp/contests/abc110/submissions/3254947
        '''

        if self._values:
            return self._values

        is_met = [True for _ in range(self.number + 1)]
        is_met[0] = False
        is_met[1] = False

        for i in range(2, self.number + 1):
            if is_met[i]:
                self._values.append(i)

                for j in range(2 * i, self.number + 1, i):
                    is_met[j] = False
        return self._values


def main():
    x = int(input())
    ps = Prime(2 * 10 ** 5)

    for pi in ps.generate():
        if pi >= x:
            print(pi)
            exit()


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np


def is_prime(a):
	if a==1:
		return False
	for k in range(2, int(np.sqrt(a)) +1):
		if a % k == 0:
			return False
	return True
def main():
	a = int(input())
	while True:
		if a==2:
			print(a)
			exit()
		else:
			if is_prime(a):
				print(a)
				exit()
			else :
				a +=1
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
import numpy as np
a=int(input())
if a==2:
    print(2)
else:
    b = int(np.sqrt(a))
    strage = list(range(b))
    tf = False
    while tf == False:
        for n in strage:
            m = n + 2
            if a % m == 0:
                a = a + 1
                tf = False
                break
            else:
                tf = True
    print(a)

Submission status: Accepted

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

while not result:
  result = True
  X += 1
  for i in range(2,X//2+1):
    if X % i == 0:
      result = False
      break
print(X)

Submission status: Accepted

Solution code:
X = int(input())
result = False

while result == False:
  result = True
  for i in range(2,-(-X//2)+1):
    if X % i == 0:
      result = False
      break
    else:
      result = True
  if not result:
    X += 1
print(X)

Submission status: Accepted

Solution code:
n=int(input())

while True:
  flag=True
  for i in range(2,n//2+1):
    if n%i == 0:
      flag=False
      break
  if flag:
    break
  n=n+1
print(n)

Submission status: Accepted

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

n = int(input())
for x in range(n,2*n):
    if func(x):
        print(x)
        break

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, 2*x):
    if is_prime(i):
        print(i)
        break

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, 2*x):
    if is_prime(i):
        print(i)
        break

Submission status: Accepted

Solution code:
def factorize(n):
    fct=[]
    b,e=2,0
    while b*b<=n:
        while n%b==0:
            n=n//b
            e=e+1
        if e>0:
            fct.append((b,e))
        b,e=b+1,0
    if n>1:
        fct.append((n,1))
    return fct
n=int(input())
while True:
    l=factorize(n)
    if len(l)==1 and l[0][1]==1:
        print(n)
        exit()
    else:
        n+=1