Problem:


Score: 300 points

Problem Statement

Find the minimum prime number greater than or equal to X.

Notes

A prime number is an integer greater than 1 that cannot be evenly divided by any positive integer except 1 and itself.

For example, 2, 3, and 5 are prime numbers, while 4 and 6 are not.

Constraints

 2 \le X \le 10^5 

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X

Output

Print the minimum prime number greater than or equal to X.

Sample Input 1

20

Sample Output 1

23

The minimum prime number greater than or equal to 20 is 23.

Sample Input 2

2

Sample Output 2

2

X itself can be a prime number.

Sample Input 3

99992

Sample Output 3

100003



Sample input:
20


Sample output:
23

Submission status: Accepted

Solution code:
import math

def 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
  
num = int(input())
 
res = True
ans = 0
if num > 2 and num%2 == 0:
  num += 1
while(res):
  if isPrime(num):
    print(num)
    break
  num += 2

Submission status: Accepted

Solution code:
import math

def resolve():
    X = int(input())

    if X == 2:
        print(2)
        return

    if X % 2 == 0:
        i = X + 1
    else:
        i = X

    while True:
        isPrime = True
        for j in range(3, int(math.sqrt(i)), 2):
            if i % j == 0:
                isPrime = False
                break        
        if isPrime:
            print(i)
            return
        i += 2


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
def pri():
    x=input().rstrip()
    x=int(x)
    k=2
    while k<x:
        a=x%k
        if a==0:
            x+=1
            k=2
        else:
            k+=1
    print(x)
pri()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from functools import lru_cache
 
@lru_cache(maxsize=100000)
def n_th_prime(n):
    if n == 0:
        return 2
    primes = [n_th_prime(k) for k in range(n)]
    k = 1
    x = primes[-1] + 1
    while True:
        for p in primes[:k]:
            if x % p == 0:
                x += 1
                break
        else:
            if x > p**2:
                k += 1
            else:
                return x

x = int(input())

k = 0
p = 2
while True:
    for i in range(k):
        p = n_th_prime(i)
        if x % p == 0:
            x += 1
            break
    else:
        if x > p**2:
            k += 1
        else:
            print(x)
            break

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


x = int(input())

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

print(x)

Submission status: Accepted

Solution code:
import math

X = int(input())
x = int(round(math.sqrt(X), 0))
flag = 0

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
x = int(input())
while True:
    k = 2
    flg = True
    while x > k**2:
        if x%k == 0:
            flg = False
            break
        k+= 1
    if flg == True:
        break
    x+=1
print(x)

Submission status: Accepted

Solution code:
X = int(input())
LEN = int(1e6)
p = [True] * LEN

p[0] = False
p[1] = False

for i in range(LEN):
  if p[i]:
    if i >= X:
      print(i)
      exit()
      
    for j in range(i * 2, LEN, i):
      p[j] = False

Submission status: Accepted

Solution code:
X = int(input())
LEN = int(1e6)
p = [True] * LEN

p[0] = False
p[1] = False

for i in range(LEN):
  if p[i]:
    for j in range(i * 2, LEN, i):
      p[j] = False

for i in range(X, LEN):
  if p[i]:
    print(i)
    exit()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
N=int(input())
def isp(N):
  if N==2:
    return(True)
  k=int(math.sqrt(N))
  
  for i in range(2,k+2):
    if N%i==0:
      return(False)
  return(True)
while isp(N)==False:
  N+=1
print(N)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
#A, B, K = map(int, input().split())
X = int(input())

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

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

Submission status: Accepted

Solution code:
import math

X = int(input())

def primeNum(target):
    dest = int(math.sqrt(target))
    for i in range(2, dest):
        if target % i == 0:
            primeNum(target + 1)
            return
    print(str(target))

primeNum(X)

Submission status: Accepted

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:
            break
    else:
        return True  #nまでの数で割り切れなかったら素数

while True:
    isprime(X)
    if isprime(X) == True:
        break
    else:
        X = 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
N = int(input())
while True:
    if is_prime(N):
        print(N)
        exit()
    N += 1

Submission status: Accepted

Solution code:
from math import sqrt

X = int(input())

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
x = int(input())
primes = [i for i in range(2 * x)]
for i, b in enumerate(primes):
    if i < 2 or b == 0:
        continue
    else:
        m = (2 * x - 1) // i
        if m > 1:
            for j in range(2, m + 1):
                primes[i * j] = 0
print(min([i for i in primes if i >= x]))

Submission status: Accepted

Solution code:
a = int(input())
def sosutyousa(a):
    src = 2    
    while src <= a:
        if src == a:
            return a
        elif a % src == 0:
            return a + 1
        else:
            src += 1
flag = sosutyousa(a)
while a != flag:
    flag = sosutyousa(flag)
    a += 1
print(a)

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(raw_input())
while True:
    if is_prime(n):
        print n
        break
    n += 1

Submission status: Accepted

Solution code:
import math

X=int(input())
ans = X

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

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

Submission status: Accepted

Solution code:
# ABC149C - Next Prime
def is_prime(n: int) -> bool:
    """
    Evaluate whether a number is prime or not.

    Args:
        n: a number to evaluate

    Returns: whether n is prime or not
    """
    if n == 2:
        return True
    if n == 1 or n % 2 == 0:
        return False
    for i in range(3, int(n ** 0.5) + 1, 2):
        if n % i == 0:
            return False
    return True


def main():
    N = int(input())
    if N != 2 and N % 2 == 0:
        N += 1
    while not is_prime(N):
        N += 2
    print(N)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
A =int(input())
def Primenumber(i):
    if i == 2:
        return 2
    for j in range(2,(i//2)+1):
        if i % j == 0:
            return Primenumber(i+1)
        elif j == i//2:
            return i
            
print(Primenumber(A))

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
def is_prime(x):
	if x <= 1:
		return False
	root_n = int(np.sqrt(x))
	for i in range(2,root_n):
		if x%i == 0:
			return False
	return True

p = n

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

def is_prime(x):
  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 isprime(n):
    judgement = True
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            judgement = False
            break
    return judgement


x = int(input())

while True:
    if isprime(x):
        answer = x
        print(answer)
        exit()
    else:
        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:
n = int(input())
x=0
while(1):
  if n ==2:
    break
  for i in range (int((-(-n**0.5//1)))):
    if n%(i+1)==0:
      x=x+1
  if x==1:
    break
  else:
    x=0
    n=n+1
print(n)

Submission status: Accepted

Solution code:
def solve(string):
    x = int(string)
    for i in range(x, 2 * x):
        for j in range(2, int(i**0.5) + 1):
            if i % j == 0:
                break
        else:
            return str(i)


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

Submission status: Accepted

Solution code:
def solve(string):
    x = int(string)
    for i in range(x, 2 * x):
        for j in range(2, int(i**0.5)):
            if i % j == 0:
                break
        else:
            return str(i)


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