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 numpy as np
X=int(input())
def seachPrimeNum(N):
    max = int(np.sqrt(N))
    seachList = [i for i in range(2,N+1)]
    primeNum = []
    while seachList[0] <= max:
        primeNum.append(seachList[0])
        tmp = seachList[0]
        seachList = [i for i in seachList if i % tmp != 0]
    primeNum.extend(seachList)
    return primeNum
B=seachPrimeNum(100100)
for i in range(len(B)):
    if B[i]>=X:
        answer=i
        break
print(B[answer])

Submission status: Accepted

Solution code:
def pr(n):
    ip = [True]*(n+1)
    ip[0] = False
    ip[1] = False
    for i in range(2,int(n**0.5)+1):
        if not ip[i]:
            continue
        for j in range(i*2,n+1,i):
            ip[j] = False
            
    return ip[n]
n = int(input())
while True:
    if pr(n) == True:
        print(n)
        exit()
    n += 1

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
# -*- Coding: utf-8 -*-
import math

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

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

x = int(input())

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

print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def is_prime(n):
    if n <= 1:
        return False
    elif n == 2:
        return True
    elif n % 2 == 0:
        return False
    for i in range(3, n, 2):
        if i * i > n:
            break
        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:
X = int(input())
sosu = "Yes"

while True:
  if X == 2:
    break
  for i in range(3, X):
    #print("i is " + str(i))
    if X % i == 0:
      sosu = "No"
      break
  if sosu == "Yes":
    break
  else:
    sosu = "Yes"
    X = X + 1

print(X)

Submission status: Accepted

Solution code:
x = int(input())

d = 2

ans = 2

if x != 2:
  while d <= 1+x//2:
    if x%d == 0:
      x += 1
      d = 2
    else:
      if d == 1+x//2:
        ans = x
        break
      else:
        d += 1
  print(ans)
else:
  print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
import math

#素数判定
def prime(n):
    if n == 2:
        return True
    elif (n < 2) or (n % 2 == 0):
        return  False
    else:
        i = 3
        while i <= math.sqrt(n):
            if n % i == 0:
                return False
            i += 2

        return True

if __name__ == "__main__":
    x = int(input())
    num = x

    while prime(num) == False:
        num += 1

    print(num)

Submission status: Accepted

Solution code:
x = int(input())
while True:
    if all(x % i != 0 for i in range(2, x)):
        print(x)
        exit()
    else:
        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
def main():
    n = int(input())
    for k in range(n, n*n, 1):
        if is_prime(k):
            print(k)
            break

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math

X = int(input())

R = X
LL = int(math.sqrt(X)) + 1

found = False
while not found:
    bflag = False
    for i in range(2, LL + 1):
        if R % i == 0 and R != i:
            R += 1
            bflag = True
            break
    found = not bflag

print('{}'.format(R))

Submission status: Accepted

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

x = int(input())
min_sosu = x
flg_found = False

for i in range(x, 1000000):
    for j in range(2, i*i):
        if i%j == 0 and j < x:
            break
        if i%j == 0 and j >= x and i == j:
            min_sosu = i
            flg_found = True
            print(min_sosu)
            break
    if flg_found:
        break

Submission status: Accepted

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


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


def main():
    n = int(input())
    for i in range(n, 100004):
        if is_prime(i):
            print(i)
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a = int(input())

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

elif a%2==0:
    k=0
    a-=1
    while k==0:
        a+=2
        count=0
        for i in range(2,a//2 + 1):
            if a%i!=0:
                count+=1
        if count==a//2 - 1:
            k=1
    print(a)
elif a%2!=0:
    k=0
    a-=2
    while k==0:
        a+=2
        count=0
        for i in range(2,a//2 + 1):
            if a%i!=0:
                count+=1
        if count==a//2 - 1:
            k=1
    print(a)

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())
res=0
if X == 2:
    pass
elif X%2 == 0:
    X = X +1
else:
    pass
for i in range(X, X+10000):
    res = i
    if isPrime(i):
        break
print(res)

Submission status: Accepted

Solution code:
import math
def trial_division(tar):
	dest  = int(math.sqrt(tar))+1
	for i in range(2,dest):
		if tar%i == 0:
			#print(int(i))
			return int(0) #not prime number
	return int(1) #prime number

x = int(input())
while trial_division(x)==0:
	x+=1
print(x)

Submission status: Accepted

Solution code:
X = int(input())

def isprime(x):
    for i in range(2,int(x),1):
        if x % i == 0:
            return False
    return True
i = X
while True:
    if isprime(i):
        break
    else:
        i += 1

print(i)

Submission status: Accepted

Solution code:
x=int(input())

import math

def trial_division(target):
    dest = int(math.sqrt(target))
 
    for i in range(2,dest):
        if target % i == 0:
            #print("False")
            return
    print(x)
    exit()

while 1:
    trial_division(x)
    x+=1

Submission status: Accepted

Solution code:
import math
x=int(input())
primemode = True
while primemode:
  sos = True
  for n in range(math.floor(math.sqrt(x))):
    if n+1 != 1:
      if x%(n+1) == 0:
        sos = False
  if sos:
    primemode = False
  else:
    x = x+1
print(x)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=int(input())

import math

def trial_division(target):
    dest = int(math.sqrt(target))
 
    for i in range(2,dest):
        if target % i == 0:
            #print("False")
            return
    print(x)
    exit()

while 1:
    trial_division(x)
    x+=1

Submission status: Accepted

Solution code:
n = int(input())


def isprime(x):
    if x == 2:
        return True
    if x < 2 or x % 2 == 0:
        return False
    i = 3
    while i <= x ** 0.5:
        if x % i == 0:
            return False
        i += 2
    return True


a = n
while not isprime(a):
    a += 1
print(a)

Submission status: Accepted

Solution code:
x = int(input())
p = x - 1
prime = False

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

Submission status: Accepted

Solution code:
x = int(input())

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

Submission status: Accepted

Solution code:
n = int(input())

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

i = n
while True:
    if isprime(i):
        break
    else:
        i += 1
print(i)

Submission status: Accepted

Solution code:
X=int(input())

answer=0
base=X
a=0

if X==2:
    print(2)
else:
    while a==0:
        for i in range(base//2):
            if base%(i+2)==0:
                base+=1
                break
            else:
                if i==base//2-1:
                    print(base)
                    a+=1
                    break

Submission status: Accepted

Solution code:
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(read())

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


for i in range(n, n*n, 1):
    if is_prime(i):
        break

print(i)

Submission status: Accepted

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

X=int(input())

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

Submission status: Accepted

Solution code:
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(read())

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


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

Submission status: Accepted

Solution code:
x = int(input())
num = 100200
arr = list(range(2,num))
arr = set(arr)
primes = {2}
floor = int(num**0.5)+2

prime = min(arr)
while prime < floor:
    prime = min(arr)
    primes.add(prime)
    nonprime = {prime * i for i in range(1,num//prime + 2)}
    arr = arr.difference(nonprime)

primes = primes.union(arr)

sol = {i for i in primes if i >= x}

print(min(sol))

Submission status: Accepted

Solution code:
import math
def main():
    X = int(input())
    if X == 2:
        print(X)
        return
    if X % 2 == 0:
        X = X + 1
    while True:
        if trial_division(X):
            print(X)
            break
        X += 2
def trial_division(t):
    d = int(math.sqrt(t))
    for i in range(2, d):
        if t % i == 0:
            return False
    return True
main()

Submission status: Accepted

Solution code:
import math
x = int(input())
prime = []
sarch = [i for i in range(2, 10 ** 6 + 1)]
while True:
    if (sarch[0] > math.sqrt(x)):
        prime.extend(sarch)
        for i in prime:
            if i >= x:
                print(i)
                exit()
    else:
        head = sarch[0]
        prime.append(head)
        sarch.pop(0)
        sarch = [num for num in sarch if num % head != 0]

Submission status: Accepted

Solution code:
def main():
    X = int(input())
    primes = [2, 3, 5, 7, 9, 11, 13]
    if X <= primes[-1] and X in primes:
        return X
    while True:
        for i in primes:
            if X % i == 0:
                break
        else:
            for i in range(primes[-1] + 2, int(X ** 0.5) + 1, 2):
                if X % i == 0:
                    break
            else:
                return X
        X += 1 

print(main())

Submission status: Accepted

Solution code:
X = int(input())

is_prime_num_list = [True] * 100005
is_prime_num_list[0] = False
is_prime_num_list[1] = False

for i in range(2, X + 1):
    if is_prime_num_list[i] == True:

        # iの倍数番目をFalseにする
        for j in range(2 * i, 100005, i):
            is_prime_num_list[j] = False

prime_num_list = [i for i, j in enumerate(is_prime_num_list) if i >= X and j == True]

print(min(prime_num_list))


'''
if is_prime_num_list[X] == True:
    print(X)
    exit()
'''

'''
while True:
    X += 1
    is_target = True
    for i in prime_num_list:
        if X % i == 0:
            is_target = False
            break

    if is_target:
        print(X)
        exit()
'''

Submission status: Accepted

Solution code:
s = [True for i in range(200000)]
s[0] = False
s[1] = False
n = int(input())
for i in range(2,len(s)):
  if not s[i]:
    continue
  for j in range(i+i, len(s), i):
    s[j] = False
for i in range(n, len(s)):
  if s[i]:
    print(i)
    break

Submission status: Accepted

Solution code:
# import numpy as np
import math
import sys
input = sys.stdin.readline

X = int(input())

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

while not is_prime(X):
    X += 1

print(X)

Submission status: Accepted

Solution code:

def is_prime(x):
    # 解説見た
    if x <= 1:
        return True
    i = 2
    while i * i <= x:
        if x % i == 0:
            return True
        i += 1
    return False


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

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# C - Next Prime
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)

Submission status: Accepted

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

x = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def prime_serch(num):
  num_p = int(math.sqrt(num))
  prime = 1
  for n in range(2, num_p):
    if num % n == 0:
      prime = 0
      break
  return prime


num = int(input())
n = 0
while n == 0:
  if prime_serch(num) == 1:
    n = 1
  num += 1
print(num - 1)

Submission status: Accepted

Solution code:
x = int(input())


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

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

Submission status: Accepted

Solution code:
X = int(input())

count = 0

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

Submission status: Accepted

Solution code:
from math import sqrt


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


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

Submission status: Accepted

Solution code:
def hantei(X):
      if X <= 1:
          return False
      for i in range(2, int(X**0.5)):
          if X%i == 0:
              return False
      return True

X = int(input())

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

Submission status: Accepted

Solution code:
import bisect
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

l = get_primenumber(100100)
a = int(input())
t = l[bisect.bisect_right(l,a)]
T =  l[bisect.bisect_left(l,a)]

if T == a:
    print(a)
else:
    print(t)

Submission status: Accepted

Solution code:
def prm(x):
  if x == 1 or x == 4:
    return False
  for i in range(2,int(x**0.5+1)):
    if x%i == 0:
      return False
  return True
X=int(input())
for i in range(X,X**2):
  if prm(i):
    print(i)
    break

Submission status: Accepted

Solution code:
def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    if n < 2:
        raise ValueError("N >= 2")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]

X = int(input())
ps = getprime(X*2)
print(min([p for p in ps if p >= X]))

Submission status: Accepted

Solution code:
import sys
def sieve(N):
    if N<2:
        prime = [False for i in range(N+1)]
        return prime
 
    prime = [True for i in range(N+1)]
    prime[0] = False
    prime[1] = False
 
    for i in range(2, int(N**0.5)+1):
        if prime[i]:
            for j in range(i*2, N+1, i):
                prime[j] = False
 
    return prime

l=sieve(100057)
x=int(input())
while True:
    if l[x]==True:
        print(x)
        sys.exit()
    x+=1

Submission status: Accepted

Solution code:
def P(n):#素数判定のアルゴリズム(O(√n))
    if type(n)!=int:raise TypeError#自然数以外はエラーを返す
    if n<1:raise ValueError#1未満は定義域を外れています
    if n==1:return -1#1は素数でも合成数でもないので負数を返す
    if n%2==0and n!=2:return 2#高速化用に2を別で判定
    a=3
    while a*a<n:#nの平方根以下のすべての奇数で割れるか判定
        if n%a==0:return a#割り切れたら最小の素因数を返す
        a+=2#奇数のみの判定なので偶数を飛ばせる
    return 0#割れなかったら(素数なら)0を返す
import math
a=int(input())
while P(a):a+=1
print(a)

Submission status: Accepted

Solution code:
import math

x = int(input())

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

    i = 2
    max_n = int(math.sqrt(n))
    while i <= max_n:
        if n % i == 0:
            return False
        i += 1
    return True
    
def next_prime(n):
    while True:
        if is_prime(n):
            return n
        n += 1

print(next_prime(x))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7 # 998244353
input=lambda:sys.stdin.readline().rstrip()
def prime(n):
    if(n<=1): return []
    S=[1]*(n+1)
    S[0]=0; S[1]=0
    for i in range(2,n):
        if(S[i]==0): continue
        for j in range(2*i,n+1,i): S[j]=0
    return [p for p in range(n+1) if(S[p])]

def resolve():
    x=int(input())
    P=prime(2*10**5)
    for p in P:
        if(p>=x):
            print(p)
            return
resolve()

Submission status: Accepted

Solution code:
x = int(input())

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

Submission status: Accepted

Solution code:
from math import sqrt

primes=[2]
flag = False
x = int(input())
if x == 2:
  print(x)
else:
  i = 3
  while True:
    for p in primes:
      if sqrt(i) < p:
        flag = True
        break
      if i % p == 0:
        break
    if flag:
      primes.append(i)
      if x <= i:
        break
      flag = False
    i+=1
  print(i)

Submission status: Accepted

Solution code:
import math
import os
n = int(input())
i = 3
data = [2]
if n is 2:
  print(n)
else:
  while True:
    flag = True
    for d in data:
      if d > math.sqrt(i):
        break
      elif i % d == 0:
        flag = False
        break
    if flag:
      if i >= n:
        break
      data.append(i)
    i += 2
  print (i)

Submission status: Accepted

Solution code:
import random


def is_prime(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

X = int(input())

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

Submission status: Accepted

Solution code:
import sys
bbn=1000000007
	
#+++++

def is_p(v):
	for i in range(2, int(v**0.5)+1):
		if v % i == 0:
			return False
	return True
						
def main():
	x = int(input())
	x=x-1
	while True:
		x+=1
		if is_p(x):
			return x
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

Solution code:
a = int(input())

import math

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

    print(n)
    exit()

while True:
  is_prime(a)
  a+=1

Submission status: Accepted

Solution code:
import copy

n = int(input())

for i in range(n, n + 1000):
  flag = True
  for j in range(2, i - 1):
    if i % j == 0:
      flag = False
      break
  if flag:
    break

print(i)

Submission status: Accepted

Solution code:
x=int(input())

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

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

Submission status: Accepted

Solution code:
a = int(input())
z = a
divide = [i for i in range(2, a) if i % 2 != 0]
divide.append(2)
divide.sort()

if a == 2:
  print(2)
  
else:
  while 1 == 1:
    for i in divide:
      start = i
      if a % i == 0:
        a += 1
        break
    if start >= z-3:
      break  
  print(a)

Submission status: Accepted

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

num = int(input())

for i in range(num,100004):
  if isPrime(i):
    print(i)
    break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x = int(input())
while True:
    if x == 2:
        break
    if x % 2 != 0:    
        for m in range(3,int(x**0.5) + 4 ,2):
            if x % m == 0 and x > m:
                break
        else:
            break
    x += 1
print (x)

Submission status: Accepted

Solution code:
import math
def get_primenumber(number):
    prime_list = []
    search_list = list(range(2,10**6+1))
    while True:
      if search_list[0] > math.sqrt(number):
        prime_list.extend(search_list)
        break
      else:
        head_num = search_list[0]
        prime_list.append(head_num)
        search_list.pop(0)
        search_list = [num for num in search_list if num % head_num != 0]
    return prime_list

x = int(input())
h = get_primenumber(x)
for i in h:
    if i >= x:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import math

X = int(input())
val = X
max_value = int(math.sqrt(val))

div_list = []
for x in range(2, max_value+1):
    for div in div_list:
        if x % div == 0:
            break
    else:
        div_list.append(x)

while True:
    for div in div_list:
        if val % div == 0:
            break
    else:
        print(val)
        break
    val += 1

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

X = int(input())
count = 0


for i in range(100000):
    for j in range(2,X):
        if X % j == 0:
            count = count + 1
            break
    if count == 0:
        break
    count = 0
    X = X + 1

print(X)

Submission status: Accepted

Solution code:
X = int(input())

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 = X
while(not is_prime(x)):
    x += 1
print(x)

Submission status: Accepted

Solution code:
import math
import sys

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

s = int(input())
a = False
while a == False:
  bb = is_prime(s)
  if bb == True:
    print(s)
    sys.exit()
  else:
    s += 1

Submission status: Accepted

Solution code:
import random

def is_prime(n):
    if n == 2: return True
    if n == 1 or n & 1 == 0: return False

    d = (n - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for k in range(100):
        a = random.randint(1, n - 1)
        t = d
        y = pow(a, t, n)

        while t != n - 1 and y != 1 and y != n - 1:
            y = (y * y) % n
            t <<= 1

        if y != n - 1 and t & 1 == 0:
            return False

    return True

x=int(input())
for i in range(x,1000000):
    if is_prime(i):
        print(i)
        break

Submission status: Accepted

Solution code:
import math

k = int(input())

ans = 0

while ans == 0:
    factor = 0
        
        # 2以外の偶数は素数ではないので無視する
    if k % 2 == 0 and k != 2:
        k +=1
        continue
        
        # 繰り返しの上限を半分にする
    for divisor in range(2, k//2):
        if k % divisor == 0:
            factor += 1
                
    if factor == 0:
        ans =k
    
    k +=1    
            
print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8
import math


def sosuu(target):

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


def main():

    i = int(input())

    while True:
        if sosuu(i):
            print(i)
            break
        else:
            i += 1

    return 0

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
a=int(input())
if a==2:
  print(a)
else:
  sosuu=1
  a=a-1
  while sosuu==1:
    a+=1
    b=2
    while a!=b:
      if a%b==0:
        sosuu=1
        break
      else:
        b+=1
        sosuu=0
  print(a)

Submission status: Accepted

Solution code:
def func(q,k=100):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    for i in range(3,k):
        x,y = q,i
        while y:
            x, y =  y, x % y
        if x != 1: continue
        if pow(i, q-1, q) != 1:
            return False
    return True
n=int(input())
while True:
    if func(n):
        break
    n=n+1
print(n)

Submission status: Accepted

Solution code:
a = int(input())

def mark(s, x):
    for i in range(x + x, len(s), x):
        s[i] = False

def sieve(n):
    s = [True] * n
    for x in range(2, int(n**0.5) + 1):
        if s[x]: mark(s, x)
    return [i for i in range(0,n) if s[i] and i >= a]

s = sieve(a * 2)
print(s[0])

Submission status: Accepted

Solution code:
x = int(input())
ps = set(range(x, 4 * x + 1))
for i in range(2, x):
    for j in range(0, 4 * x + 1, i):
        if j in ps:
            ps.remove(j)
print(min(ps))

Submission status: Accepted

Solution code:
from math import sqrt, ceil

X = int(input())

temp = [True]*(10**5+4)
temp[0] = temp[1] = False
for i in range(2, ceil(sqrt(10**5+4))):
    if temp[i]:
        temp[i+i::i] = [False]*(len(temp[i+i::i]))
for j in range(X, 10**5+4):
    if temp[j] == True:
      print(j)
      exit()

Submission status: Accepted

Solution code:
def isPrime(n): 

	if n <= 1: 
		return False

	for i in range(2, n): 
		if n % i == 0: 
			return False; 

	return True

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

Submission status: Accepted

Solution code:
def isPrime(n): 

	# Corner case 
	if n <= 1: 
		return False

	# Check from 2 to n-1 
	for i in range(2, n): 
		if n % i == 0: 
			return False; 

	return True

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

Submission status: Accepted

Solution code:
# coding: utf-8
import math


def isprime(target):

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


def main():

    i = int(input())

    while True:
        if isprime(i):
            print(i)
            break
        else:
            i += 1

    return 0

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())
c=0
for k in range(x,100004):

  if is_prime(k) == 1:
    print(k)
    break

Submission status: Accepted

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

if X < 4:
  print(X)
  sys.exit()

if X%2 ==0:
  A = X-1
else:
  A = X-2

ans = 0
while ans == 0:
  A += 2
  for n in range(2,int(A/2)+1):
    ans = A
    if A%n == 0:
      ans = 0
      break

ans = A
print(ans)

Submission status: Accepted

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

if X == 2 or X == 3:
    print(X)
    exit()

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