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: Wrong Answer

Solution code:
n=int(input())+1
i=n if n%2==1 else n+1
er=list(range(3,n-1))
for j in range(2,n-1):
    if j in er:
        er=[x for x in er if x==j or not x%j==0]
while True:
    f=True
    for y in er:
        if i%y==0:
            f=False
            break
    if f:
        print(i)
        break
    i+=2

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
x = input()

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

is_sosu(int(x))

Submission status: Wrong Answer

Solution code:
x = input()

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

is_sosu(int(x))

Submission status: Wrong Answer

Solution code:
x = input()

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

is_sosu(int(x))

Submission status: Wrong Answer

Solution code:
x = input()

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

is_sosu(int(x))

Submission status: Wrong Answer

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:
    return True
  else:
    return False

X = int(input())
import math

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

Submission status: Wrong Answer

Solution code:
X = int(input())

r = X

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
def is_prime(n):
    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: Wrong Answer

Solution code:
import sys

x = int(input())

def is_prime(n):
    a = {}
    while n % 2 == 0:
        if 2 in a:
            a[2] += 1
        else:
            a[2] = 1
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            if f in a:
                a[f] += 1
            else:
                a[f] = 1
            n //= f
        else:
            f += 2
    if n != 1:
        a[n] = 1
    if len(list(a.keys())) == 1 and a[list(a.keys())[0]] == 1:
        return True
    else:
        return False

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

Submission status: Wrong Answer

Solution code:
prims = list()

prims.append(2)

base = int(input())

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

# 入力値までの素数を作る
for n in range(base):
  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: Wrong Answer

Solution code:
X = int(input())

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

Submission status: Wrong Answer

Solution code:
X = int(input())

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=int(input())

for i in range(a+1,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: Wrong Answer

Solution code:
a=int(input())

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

Submission status: Wrong Answer

Solution code:
a=int(input())

for i in range(a+1,10**5):
  for j in range(2,i):
    if i%j!=0:
      print(i)
      exit()

Submission status: Wrong Answer

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

q = q + 1
while True:
  if is_prime(q):
    print(q)
    sys.exit()
  q = q + 1

Submission status: Wrong Answer

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

Solution code:
n = 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)

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

Submission status: Wrong Answer

Solution code:
n = 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)

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

Submission status: Wrong Answer

Solution code:
import numpy as np
a=int(input())
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: Wrong Answer

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

import numpy as np
X =int(input())

if X == 2:
    print(X)

else:
    s = np.array([2])
    
    for i in range(2, 10000):
        res = True
        for j in s:
            if (i % j) == 0:
                res = False
                break
        if res == True:
            s = np.append(s, i)
            if i >= X:
                print(i)
                break

Submission status: Wrong Answer

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

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

print(X)

Submission status: Wrong Answer

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

n = int(input())
end = 10**5 + 1
for x in range(n,end):
    tmp = func(x)
    if tmp != -1:
        print(tmp)
        break

Submission status: Wrong Answer

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

n = int(input())
end = 10**5 + 1
for x in range(n,end):
    tmp = func(x)
    if tmp != -1:
        print(tmp)
        break

Submission status: Wrong Answer

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

n = int(input())
end = 10**5 + 1
for x in range(n,end):
    tmp = func(x)
    if tmp != -1:
        print(tmp)
        break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#素数判定
import math
def is_prime(n):
    if n == 1: return False

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

Submission status: Wrong Answer

Solution code:
X=int(input())
testX=int(X**(1/2))+2
primeset=set()
for i in range(2,testX):
    num=0
    for p in primeset:
        if i%p != 0:
            pass
        else:
            num=1
            break
    if num==0:
        primeset.add(i)
num=0
while num == 0:
    num=1
    for p in primeset:
        if X%p != 0:
            pass
        else:
            X+=1
            num=0
            break
    if num == 1:
        print(X)

Submission status: Wrong Answer

Solution code:
X=int(input())
testX=int(X**(1/2))+2
primeset={2}
for i in range(3,testX):
    num=0
    for p in primeset:
        if i%p != 0:
            pass
        else:
            num=1
            break
    if num==0:
        primeset.add(i)
num = 0 
while num == 0:
    num=1
    for p in primeset:
        if X%p != 0:
            pass
        else:
            X+=1
            num=0
            break
    if num == 1:
        print(X)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(X)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

print(X)

Submission status: Wrong Answer

Solution code:
nn=int(input())
n=10**5+1
ar=[0]*(n)
ar[1]=0
ans=0
pre=1
for i in range(2,n):
    if ar[i]==0:

        for j in range(2*i,n,i):
            ar[j]=1
ans=1
for i in range(2,nn+1):
    if ar[i]==0:
        ans=i
print(ans)

Submission status: Wrong Answer

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

    number += 1

Submission status: Wrong Answer

Solution code:
x = int(input())
y = x + 30
is_prime = [False] * 2 + [True for _ in range(2, y+1)]
prime = []
for i in range(2, y+1):
	for j in range(i*2, y+1, i):
		is_prime[j] = False
for i in range(y+1):
	if is_prime[i]:
		prime.append(i)
for i in range(len(prime)):
  if prime[i] >= x:
    print(prime[i])
    break
  else:
    continue

Submission status: Wrong Answer

Solution code:
x = int(input())
a = False
while a == True:
  b = range(x) + 1
  c = x/b
  d = [d.is_integer() for d in c[1:-1]]
  if any(d):
    a = True
    break
  x = x + 1
print(x)

Submission status: Wrong Answer

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

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

for i in range(100000):
    if (x + i)%2 == 0:
        continue
    elif (x+i)%3 == 0:
        continue
    else:
        if isPrime(x+i):
            break
        else:
            continue
print(x+i)

Submission status: Wrong Answer

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

def solve():
  x = int(input())
  for i in range(x+2,10**6+15):
    if isprime(i):
      print(i)
      exit()
      
solve()

Submission status: Wrong Answer

Solution code:
from math import ceil
x=int(input())
i=0
ok=True
if x<=2:
  print(2)
elif x==3:
  print(3)
elif x==4:
  print(5)
else:
  while 1:
    for j in range(2,ceil((x+i)**0.5)):
      if (x+i)%(j+1)==0:
        ok=False
    if ok:
      print(x+i)
      exit()
    i+=1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
  x = int(input())
  sosu = [2]
  tgt = 2
  is_sosu = True
  while(1):
    for i in sosu:
      if tgt % i == 0:
        is_sosu = False
        break
    if is_sosu:
      sosu.append(tgt)
    if tgt >= x and is_sosu:
      print(tgt)
      break
    else:
      tgt += 1
      is_sosu = True

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
import math
numX = int(input())
 
result = -1
 
if numX <= 2:
  result = 2
elif numX % 2 == 0:
  numX += 1
  while True:
    upper = math.ceil(math.sqrt(numX))
    isPrime = True
    for i in range(3, upper, 2):
      if numX % i == 0:
        isPrime = False
        break
    if isPrime == True:
      result = numX
      break
    numX += 2
      
print(result)

Submission status: Wrong Answer

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

result = -1

if numX <= 2:
  result = 2
elif numX % 2 == 0:
  numX += 1
  while True:
    upper = math.ceil(math.sqrt(numX))
    isPrime = True
    for i in range(3, upper, 2):
      if numX % i == 0:
        isPrime = False
        break
    if isPrime == True:
      result = numX
      break
    numX += 2
      
print(numX)

Submission status: Wrong Answer

Solution code:
nn=int(input())
n=100
a=[0]*n
a[1]=0
ans=1
pre=1
if nn==1:
    print(1)
else:
        
    for i in range(2,n):
        if a[i]==0:
    
            if i>=nn:
                print(i)
                break
            pre =ans
            ans=i
            
            for j in range(i+1,n):
                #print(i,j,a[j])
                if j%i==0:
                    a[j]=1
                    #print("asdf",i,j,a[j])
    """
    for i in range(nn,n):
        if a[i]==0:
            print(i)
    
            
                    
                    
    """

Submission status: Wrong Answer

Solution code:
n = int(input())
for i in range(n, 10**5) :
    for j in range(2, i) :
        if i % j == 0 :
            break
    else :
        print(i)
        break

Submission status: Wrong Answer

Solution code:
import math as m

x = int(input())

def isPrime(x):
	if x % 2 == 0:
		return False
	
	n = m.floor(m.sqrt(x))
	
	for i in range(3, n, 2):
		if x % i == 0:
			return False
	
	return True



for i in range(x, 2 * x - 1):
	if isPrime(i):
		print(i)
		break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from math import sqrt
X = int(input())
def is_prime_next(X):
    X_sqrt = int((sqrt(X)+1)/6) 
    if X==2 or X==3:
        return X
    if X%2 == 0:
        return None
    if X%3 == 0:
        return None
    for i in range(1, X_sqrt+1):
        if X % (6*i+1) == 0 or X % (6*i+5) == 0:
            return None
    return X
while(1):
    X_keep = is_prime_next(X)
    if X_keep != None:
        break
    X += 1
print(X)

Submission status: Wrong Answer

Solution code:
from math import sqrt
X = int(input())
def is_prime_next(X):
    X_sqrt = int((sqrt(X+1))/6) 
    if X==2 or X==3:
        return X
    if X%2 == 0:
        return None
    if X%3 == 0:
        return None
    for i in range(1, X_sqrt+1):
        if X % (6*i+1) == 0 or X % (6*i+5) == 0:
            return None
    return X
while(1):
    X_keep = is_prime_next(X)
    if X_keep != None:
        break
    X += 1
print(X)

Submission status: Wrong Answer

Solution code:
from math import sqrt
X = int(input())
def is_prime_next(X):
    X_sqrt = int((sqrt(X)-5)/6) 
    if X==2 or X==3:
        return X
    if X%2 == 0:
        return None
    if X%3 == 0:
        return None
    for i in range(1, X_sqrt):
        if X % (6*i+1) == 0 or X % (6*i+5) == 0:
            return None
    return X
while(1):
    X_keep = is_prime_next(X)
    if X_keep != None:
        break
    X += 1
print(X)

Submission status: Wrong Answer

Solution code:
from math import sqrt
X = int(input())
def is_prime_next(X):
    X_sqrt = int(sqrt(X)/6) 
    if X==2 or X==3:
        return X
    if X%2 == 0:
        return None
    if X%3 == 0:
        return None
    for i in range(1, X_sqrt):
        if X % (6*i+1) == 0 or X % (6*i+5) == 0:
            return None
    return X
while(1):
    X_keep = is_prime_next(X)
    if X_keep != None:
        break
    X += 1
print(X)

Submission status: Wrong Answer

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