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:
from sys import stdin
import math

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

x = int(stdin.readline().strip())
while(True):
  if is_prime(x):
    break
  x += 1
  
print(x)

Submission status: Accepted

Solution code:
import math


def is_prme_number(num):
    if num == 1:
        return False

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

    return True


def main():
    x = int(input())
    while True:
        if is_prme_number(x):
            break
        x += 1
    print(x)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
x = int(input())
if x == 2:
    print(2)
    exit()
elif x%2 == 0:
    x += 1
 
def get_prime(n):
    p = [2]
    for i in range(3, n, 2):
        if all(i%j!=0 for j in p):
            p.append(i)
    return p
 
p = get_prime(x)
 
while True:
    for prime in p:
        if x%prime == 0:
            break
    else:
        print(x)
        break
    x += 2

Submission status: Accepted

Solution code:
x = int(input())

def get_prime(n):
    p = [2]
    for i in range(3, n, 2):
        if all(i%j!=0 for j in p):
            p.append(i)
    return p

p = get_prime(x)

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

Submission status: Accepted

Solution code:
import math

X=int(input())


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

Submission status: Accepted

Solution code:
# import sys
import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy
# import bisect
# import numpy as np
# from scipy.special import comb

# def my_input(): return sys.stdin.readline().rstrip()
# sys.setrecursionlimit(100000)
# INF = 1001001001001
# MOD = 1000000007


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
p = int(raw_input())

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

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

Submission status: Accepted

Solution code:

def s0():return input()
def s1():return input().split()
def s2(n):return [input() for x in range(n)]
def s3(n):return [input().split() for _ in range(n)]
def s4(n): return [[x for x in s] for s in s2(n)]
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]
def t3(n):return [tuple(int(x) for x in input().split()) for _ in range(n)]
def p0(b,yes="Yes",no="No"): print(yes if b else no)
# from sys import setrecursionlimit
# setrecursionlimit(1000000)
# from collections import Counter,deque,defaultdict
# import itertools
# import math
# import networkx
# from bisect import bisect_left,bisect_right
# from heapq import heapify,heappush,heappop

X=n0()

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

sosuu=primes((10**5)+1000)
while True:
    if X in sosuu:
        print(X)
        break
    X+=1

Submission status: Accepted

Solution code:
import math

X = int(input())
for i in range(X,10**6):
    for j in range(2,int(math.sqrt(X))+1):
        if i%j==0:
            break
    else:
        ans = i
        break
print(ans)

Submission status: Accepted

Solution code:
X = int(input())

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

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

Submission status: Accepted

Solution code:
X = int(input())

fact = [True] * (10 ** 5 + 1000)
fact[0],fact[1] = False,False
for i in range(2,len(fact)):
  if fact[i]:
    for j in range(i * 2, len(fact), i):
      fact[j] = False
      
for i in range(X,len(fact)):
  if fact[i]:
    print(i)
    break

Submission status: Accepted

Solution code:
x=int(input())
ans=False
for i in range(x,10**9):
    if ans==True:
        break
    else:
        cnt=0
        for j in range(2,i+1):
            if i%j==0 and j!=i:
                continue
            else:
                cnt+=1
                if cnt==i-1:
                    print(i)
                    ans=True

Submission status: Accepted

Solution code:
import math

def isPrimeNumber(_val):
	if _val < 2:return False
	if _val == 2:return True
	if _val % 2 == 0:return False

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

	return True

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

Submission status: Accepted

Solution code:
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 [i for i in range(n + 1) if is_prime[i]]


X = int(input())
p = primes(10 ** 5 + 3)
print([i for i in p if i >= X][0])

Submission status: Accepted

Solution code:
# coding: utf-8
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

# 関数の呼び出し
P=callIsPrime(2*10**5)

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

Submission status: Accepted

Solution code:
X = int(input())
while any(X % i == 0 for i in range(2, int(X ** 0.5) + 1)):
    X += 1
print(X)

Submission status: Accepted

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

for i in range(x,10**111):
  for j in range(2,(i//2)+2):
    tmp += 1
    if tmp == (i//2):
      print(i)
      exit()
    elif i%j == 0:
      tmp = 0
      break

Submission status: Accepted

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

if x == 2:
  print(2)
  exit()
for i in range(x,10**111):
  for j in range(2,(i//2)+2):
    tmp += 1
    if i%j == 0:
      tmp = 0
      break
    elif tmp == (i//2):
      print(i)
      exit()

Submission status: Accepted

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

if x == 2:
  print(2)
  exit()
for i in range(x,10**111):
  for j in range(2,(i//2)+2):
    tmp += 1
    if i%j == 0:
      break
    elif tmp == (i//2):
      print(i)
      exit()

Submission status: Accepted

Solution code:
import re
def main():
    X=int(input()) 
    while True:
        if is_prime(X):
            print(X)
            return
        X += 1


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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from bisect import bisect_left


def get_primes(n):
    prime = []
    limit = n ** 0.5
    data = [i + 1 for i in range(1, n)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]


X = int(input())
primes = get_primes(10 ** 5 + 3)
print(primes[bisect_left(primes, X)])

Submission status: Accepted

Solution code:
X = int(input())
for x in range(X, 10**6):
  if all(x % i != 0 for i in range(2, x)):
    print(x)
    break

Submission status: Accepted

Solution code:
x = int(input())

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=int(input())
f=0
if x == 2:
	print(2)
else:
	for i in range(x,10**6):
		for j in range(2,i//2+2):
			if i%j == 0:
				break
		else:
			f=i
			break
	print(f)

Submission status: Accepted

Solution code:
N = int(input())

ans = -1
x = N
while(ans == -1):
    if all([x % i != 0 for i in range(2, x)]):
        ans = x
    else:
        x += 1
print(ans)

Submission status: Accepted

Solution code:
## C - Next Prime　https://atcoder.jp/contests/abc149/tasks/abc149_c>
Number=int(input())
flg =0

if Number ==2: #2だったらflg＝1にして終了したい
    flg=1
    print(Number)
elif Number%2==0:
    Number+=1

Odd_Number_List =[i for i in range(3,Number,2)]

while flg==0:
    Amari_List = list(map(lambda x:Number%x,Odd_Number_List))
    if Amari_List.count(0)==0:
        flg=1
        print(Number)
        
    else:
        Odd_Number_List.append(Number)
        Number+=2

Submission status: Accepted

Solution code:
x = int(input())

while True:
  n = 2
  while x % n != 0 and n <= x/2:
    n += 1
  if n < x/2:
    x += 1
    
  else:
    print(x)
    break

Submission status: Accepted

Solution code:
def prime(N):
    p=set(range(2,N+1))
    for i in range(int(N**.5)+1):
        if i in p:
            p-=set(range(i*2,N+1,i))
    return p
N=2*10**5
p=prime(N)
X=int(input())
for i in range(X,N+1):
    if i in p:
        print(i)
        break

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

i = x
while is_prime(i) == False:
    i += 1
print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools

rl = sys.stdin.readline
x = int(rl())
while True:
    if x == 2:
        print(2)
        break
    if x % 2:
      for i in range(3, x//2, 2):
        if x % i == 0:
            break
      else:
        print(x)
        break
    x += 1

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

#素数判定
def is_prime(num):
	if num < 2:
		return False
	if num in [2, 3, 5]:
		return True
	if num%2 == 0 or num%3 == 0 or num%5 == 0:
		return False
	prime = 7
	step = 4
	num_sqrt = sqrt(num)
	while prime <= num_sqrt:
		if num%prime == 0:
			return False
		prime += step
		step = 6 - step
	return True

X = INT()

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

Submission status: Accepted

Solution code:
def is_prime(q):
    if q < 2:
        return False

    p = 2
    while p * p < q:
        if q % p == 0:
            return False
        p += 1

    return True


X = int(input())

if not is_prime(X):
    if X & 1 == 0:
        X += 1

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

print(X)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
X = int(input())

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys
sys.setrecursionlimit(300000)

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

def solve(X: int):
    while True:
        if is_prime(X):
            ret = X
            break
        X += 1
    print(ret)
    return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

ans = -1
x = N
while(ans == -1):
    if all([x % i != 0 for i in range(2, x)]):
        ans = x
    else:
        x += 1
print(ans)

Submission status: Accepted

Solution code:
import math
import sys
X = int(input())
flag = 0
cnt = 0

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

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

print(result)

Submission status: Accepted

Solution code:
n=int(input())

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

print(n)

Submission status: Accepted

Solution code:
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))



X=int(input())

prime_l=[0]*(2*X)
for  i in range(2,X):
    if(prime_l[i]==0):
        for j in range(1,(2*X)//i):
            prime_l[i*j]+=1
        
while(1):
    if(prime_l[X]==0):
        print(X)
        sys.exit(0)
    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
n = int(input())
while n:
    if is_prime(n):
        print(n)
        break
    n += 1

Submission status: Accepted

Solution code:
import math


# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


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

    return True


n = inp()

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

Submission status: Accepted

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

n = 10**6
flag = [True]*(n+1)

for i in range(4, n+1, 2):
  flag[i] = False
  
t = int(n**0.5)+1
for i in range(3, t, 2):
  for j in range(i+i, n+1, i):
    flag[j] = False

for i in range(x,n+1):
  if flag[i]:
    print(i)
    exit()

Submission status: Accepted

Solution code:
import math

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

    return True

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

Submission status: Accepted

Solution code:
x=int(input())

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

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

Submission status: Accepted

Solution code:
import math
from collections import deque
from collections import defaultdict

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

x = readInt()
if x==2:
	print(x)
	exit()
if x%2==0:
	x+=1

for i in range(x,10**6,2):
	flg = 1
	for j in range(3,int(i**0.5),2):
		if i%j==0:
			flg = 0
			break
	if flg:
		print(i)
		break

Submission status: Accepted

Solution code:
import bisect


def read():
    X = int(input())
    return X,

def sieve(n):
    is_prime = [True for i in range(n+1)]
    is_prime[0] = False
    is_prime[1] = False
    primes = []
    for i in range(2, n+1):
        if is_prime[i]:
            primes.append(i)
            for j in range(i+i, n+1, i):
                is_prime[j] = False
    return primes

def solve(X):
    primes = sieve(2*X)
    idx = bisect.bisect_left(primes, X)
    return primes[idx]

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))

Submission status: Accepted

Solution code:
n = int(input())

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:
x = int(input()) # 素数
ans = -1
if x == 2: ans = 2
for i in range(x, x+10**5+1):
    f = True
    for j in range(2, int(x**0.5)):
        if i%j==0:
            f = False
            break
    if f:
        ans = i
        break
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

X = INT()
ans = 0
def DFS(X):
	for i in range(2, int(sqrt(X))+1):
		#print(i, X)
		if X%i == 0:
			return DFS(X+1)
			break
	else:
		return X

print(DFS(X))

Submission status: Accepted

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

half = int(X/2)
i = X
while i >=X:
    for j in range(2,int(i/2)):
        if fractions.gcd(i,j) == 1:
            pass

        else:
            i += 1
            continue

    print(i)
    exit()

Submission status: Accepted

Solution code:
x = int(input())
if x == 2:
    print(2)
    exit()
i = 3
f = False
while True:
    if x % 2 == 0:
        x += 1
        continue
    while i * i <= x:
        if x % i == 0:
            i += 2
            f = True
            break
        else:
            i += 2
    if not f:
        print(x)
        exit()
    x += 1
    i = 3
    f = False

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def seachPrimeNum(N):
    max = int(numpy.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
prime = seachPrimeNum(10**5 + 3)
X = I()

print(min([i for i in prime if i >= X]))

Submission status: Accepted

Solution code:
import numpy as np

X= int(input())

ans = X
#x が素数か判定
def solve(x):
    for n in range( 2, int(np.sqrt(x))+1 ):
        if x%n ==0:
            return False
    return True

while True:
    if solve(ans):
        break
    ans += 1

print(ans)

Submission status: Accepted

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

while ok == False:
    ok = True
    for i in range(2, int(x/2)):
        if x%i == 0:
            ok = False
            x += 1
            #print("####")
            break
    if ok == True:
        print(x)
        break

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X = int(input())

i=X
isSosu=False
while True:
  if i==2:
    print(i)
    break

  j=2
  while j*j<=i:
    if i%j==0:
      break
    j+=1

    if j*j>i :
      print(i)
      isSosu=True
      break

  i+=1
  if isSosu:
    break

Submission status: Accepted

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

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

    if flag:
        print(x)
        sys.exit()

    x += 1

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(X,10**6+1):
    if is_prime(i):
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
import numpy as np
while True:
  r=True
  #print(n)

  for ii in np.arange(2,n//2):
    #print(n//(ii+1),n/(ii+1))
    if n//(ii+1)==n/(ii+1):
      r=False
      break

  #exit()
  if r:
    print(n)
    exit()
  n+=1

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


i = X

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

print(i)

Submission status: Accepted

Solution code:
X=int(input())

for i in range(X,10**5+3+1):
    for j in range(2,10**5):
        a=True
        if i!=j:
            if i%j==0:
                a=False
                break
        else:
            None
    if a==True:
        print(i)
        break

Submission status: Accepted

Solution code:

## coding: UTF-8
X = int(input())

N = 10**5 + 10
#素数列挙
Fresh = [False, False] + [True] * (N-1)

for i in range(int((N+1)**0.5) + 1):
#for i in range(N+1):
    if(Fresh[i] == True):
        for j in range(i*2, N+1, i):
            Fresh[j] = False
        #print(Fresh)

#print([i for i in range(N+1) if Fresh[i] == True])

for i in range(X, N+1):
    if(Fresh[i] == True):
        print(i)
        break



#print(Fresh)

Submission status: Accepted

Solution code:
import numpy as np

def Eratosthenes(n):
	''' n 以下の素数をエラトステネスの篩で生成 '''
	tbl = np.ones(n+1, dtype=bool)
	tbl[0:2] = False
	for i in range(2, int(np.sqrt(n))+1):
		if tbl[i]:
			tbl[2*i::i] = False
	return np.arange(n+1)[tbl]

x = int(input())

prime = Eratosthenes(100003)
for i, p in enumerate(prime):
    if p >= x:
        print(prime[i])
        break

Submission status: Accepted

Solution code:
X = int(input())

def is_prime(n):
  if n == 2:
    return True
  elif n == 1 or n%2 ==0:
    return False
  else:
    m = 3
    while m*m <= n:
      if n % m == 0:
        return False
      else:
        m += 2
    return True

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

Submission status: Accepted

Solution code:
import math

x=int(input())

for i in range(x,10**5+100):
    fact_flag = True
    for divisor in range(2,math.floor(math.sqrt(i)+1)):
        if i % divisor ==0:
            fact_flag = False
            break
    if fact_flag:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math as mt

s = int(input())
def check(x):
    a = [i for i in range(2,int(mt.sqrt(x))+1,1)]
    if all([x%j != 0 for j in a]):
        return False
    else:
        return True

f = True
while f:
    f = check(s)
    s+=1

print(s-1)

Submission status: Accepted

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

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

while key == 0:
    if prim(X):
        key = 1
        break
    X += 1

print(X)