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

Submission status: Accepted

Solution code:
X=int(input())
import numpy as np
def prime(n):
  prime=True
  for i in range(2,int(np.sqrt(n))+1):
    if n%i==0:
      prime=False
      break
  return prime
count =X
while prime(count)==False:
  count=count+1
print(count)

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())
primeList = primes(10**6)
a = 10**9
ans = 0

for i in primeList:
    if abs(x-i) <= a and x <= i:
        a = abs(x-i)
        ans = i

print(ans)

Submission status: Accepted

Solution code:
X = int(input())
red = 0
if X ==2:
    red = 1
while red == 0:
    red = 1
    for i in range(2,X):
        #print('i='+str(i)+' X='+str(X)+' X%i='+str(X % i)+' red ='+str(red))
        red =min(red, X % i)
    if red ==0:
        X = X+1
    
print(X)

Submission status: Accepted

Solution code:
X = int(input())

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

print(X)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

x = int(input())

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

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

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

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:
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:
import math


def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    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]
li = get_sieve_of_eratosthenes(pow(10,5)+1000)

X = int(input())
k = X
while True:
    if k in li:
        print(k)
        break
    k += 1

Submission status: Accepted

Solution code:
x = int(input())

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

#引数nが素数かどうかを判定
def is_prime(n):
    for i in range(2, int(math.sqrt(n))+1):
        if n%i == 0:
            return False
    return True

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

Submission status: Accepted

Solution code:
import sys
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())

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

for i in range(x,int(1e5)+100):
    for j in range(2,x):
        if i % j == 0:
            break
        elif j == x-1:
            print(i)
            sys.exit()

Submission status: Accepted

Solution code:
import math
import sys
N = int(input())
N_next = math.ceil((math.sqrt(N)+1)**2)
#print(N_next)

    
    
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, n + 1):
        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]]
    
#print(primes(7)[-1])
for i in range(N,N_next):
    if primes(i)[-1] >= N:
        print(i)
        sys.exit()

Submission status: Accepted

Solution code:
x = int(input())
# 例 x =14
# 14/2 == 0(break)　x+= 1 ,15/3 == 0(break) x+= 1 ,16/2 = 0(break) x+= 1 ,17は割り切れない（素数）のでelse
while True:
    for i in range(2,x):
        if x%i == 0:
            break
    else:
        print(x)
        break
    x += 1

Submission status: Accepted

Solution code:
import math
x = int(input().split()[0])
def get_sieve_of_eratosthenes(n):
    prime = []
    limit = math.sqrt(n)
    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]

data = get_sieve_of_eratosthenes(2*x+10)
for i in data:
  if i >= x:
    print(i)
    break

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:
def prime(n):
    n *= 2
    flag = [True] * (n - 1)
    for i in range(n - 1):
        if flag[i] == True:
            if i + 2 >= n // 2:
                return i + 2
            num = i
            while num <= n - 2:
                flag[num] = False
                num += i + 2
n = int(input())
print(prime(n))

Submission status: Accepted

Solution code:
import math

X = int(input())

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

def prime(n):
    ans = 2
    for i in range(n, 10**5+4):
        if(isprime(i)):
            ans = i        
            break
    return ans
 
print(prime(X))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x = int(read())
temp = x
while True:
    flag = True
    for i in range(2, int(temp ** 0.5)):
        if (temp % i == 0):
            flag = False
            break
        else:
            continue
    if (flag is False):
        temp += 1
    else:
        print(temp)
        exit()

Submission status: Accepted

Solution code:
x = int(input())
end = int(x**(1/2))
for i in range(x,x+1000):
  if all([i%j!=0 for j in range(2,end)]):
    print(i)
    break

Submission status: Accepted

Solution code:
import math
x=int(input())
for i in range(x,100004):
  for j in range(2,math.floor(math.sqrt(i))+1):
    if i%j==0:
      break
  else:
    print(i)
    exit()

Submission status: Accepted

Solution code:
x=int(input())
while any(x%i<1 for i in range(2,int(x**.5)+1)): x+=1
print(x)

Submission status: Accepted

Solution code:
X = int(input())

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

Submission status: Accepted

Solution code:
maxA = 10**5 + 3

X = int(input())

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

for i in range(X, maxA+1):
    if isPrime(i):
        print(i)
        break

Submission status: Accepted

Solution code:
maxA = 10**6

X = int(input())

def getIsPrimes(n):
    isPrimes = [False]*2 + [True]*(n-1)
    for x in range(2*2, n+1, 2):
        isPrimes[x] = False
    for d in range(3, int(n**0.5)+1):
        if isPrimes[d]:
            for x in range(d*d, n+1, d):
                isPrimes[x] = False
    return isPrimes

isPrimes = getIsPrimes(maxA)

for i in range(X, maxA+1):
    if isPrimes[i]:
        print(i)
        break

Submission status: Accepted

Solution code:
from collections import deque

X = int(input())
N = 10**5+4
N_sq=N**(1/2)

check = deque(range(2,N+1))
search = deque([])

for n in range(N):
    if len(check)<=0:
        break
        
    c = check.popleft()
    search.append(c)

    check = deque([ _ for _ in check if _%c != 0])
    
    if c > N_sq:
        search.extend(check)
        break
        
for s in search:
    if X <= s:
        print(s)
        break

Submission status: Accepted

Solution code:
x=int(input())
if x==2:
    print(2)
else:
    t=1
    if x%2==0:
        x+=1
    while t==1:
        t=0
        k=int(x/2)
        for i in range(3,k):
            if x%i==0:
                t=1
                x+=2
                break
    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())
Flag = True
while Flag:
    if Is_Prime(X):
        Flag = False
    else:
        X += 1
print(X)

Submission status: Accepted

Solution code:
def sosu(p):
	if p==2:
		return True
	l=int(p**0.5)+1
	for i in range(2,l+1):
		if p%i==0:
			return False
	return True
x=int(input())
x+=1 if x!=2 and x%2==0 else 0
while sosu(x)==False:
	x+=2
print(x)

Submission status: Accepted

Solution code:
x=int(input())
a=0
s=0
while s<1:
    t=0
    for i in range(2,x):
        if x%i==0:
            t+=1
    if  t==0:
        a=x
        s+=1
    else:
        x+=1
print(a)

Submission status: Accepted

Solution code:
a = (int)(input())

flag = [False] * (a * 2 + 1)
sosu = []

# 最初に素数を消す
for i in range(2, len(flag)):
    if i * i < a * 2:
        flag[i] = True
        sosu.append(i)
#print("flag = {}".format(flag))

# ふるいにかける
for i in sosu:
    for j in range(i, len(flag), i):
        flag[j] = True
#print("flag = {}".format(flag))

# 答えは？
ret = 2
for i in range(a, len(flag)):
    if flag[i] == False:
        ret = i
        break 

print("{}".format(ret))

Submission status: Accepted

Solution code:
# ans

X = int(input())

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
def is_prime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

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

    return True

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

Submission status: Accepted

Solution code:
x=int(input())
flag=True
while flag:
    i=2
    fla=True
    while i<=x**0.5:
        if x%i==0:
            fla=False
            break
        else:
            if i==2:
                i+=1
            else:
                i+=2
    if fla==False:
        x+=1
    else:
        print(x)
        flag=False

Submission status: Accepted

Solution code:
import math
def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False
    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True
X=int(input())
i=X
while True:
    if isPrime(i)==True:
        print(i)
        break
    i+=1

Submission status: Accepted

Solution code:
x = int(input())

def prime(a: int):
    for i in range(2,a):
        if a%i==0:
            return False
        
    return True

for i in range(x,10**7):
    if prime(i):
        print(i)
        break

Submission status: Accepted

Solution code:
X = int(input())

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

prime = [2]
k = 3
while True:
    isPrime = True
    maxK = int(k ** 0.5) + 1
    for p in prime:
        if p >= maxK:
            break
        isPrime &= (k % p != 0)
    if isPrime:
        prime.append(k)
        if k >= X:
            break
    k += 2
print(prime[-1])

Submission status: Accepted

Solution code:
import math, sys
X = int(input())
 
while True:
    for k in range(2, int(math.sqrt(X)+1)):
        if X % k == 0:
            X += 1
            break
    else:
        print(X)
        sys.exit(0)

Submission status: Accepted

Solution code:
import math
 
def get_sieve_of_eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = []
    limit = math.sqrt(n)
    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]
 
if __name__=='__main__':
  x=int(input())
  ans=get_sieve_of_eratosthenes(10**5+100)
  for i in ans:
    if i<x:
      continue
    else:
      print(i)
      break

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Next Prime
https://atcoder.jp/contests/abc149/tasks/abc149_c

"""
import sys

import numpy as np
from bisect import bisect_left

limit = 10**5 + 10

sieve = np.ones(limit, dtype=bool)
sieve[0] = sieve[1] = 0
sieve[2*2::2] = 0
for i in range(3, int(len(sieve)**0.5)+1, 2):
    if sieve[i]:
        sieve[i*i::i] = 0
primes = [i for i, x in enumerate(sieve) if x]


def main(args):
    X = int(input())
    print(primes[bisect_left(primes, X)])


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

x = int(input())

i = 0
while True:
    if nextprime(x+i):
        print(x+i)
        exit(0)
    i += 1

Submission status: Accepted

Solution code:
import math
x = int(input())
if x ==2:
    print(2)
    exit()
while True:
    result = math.ceil((x-3)/2)
    for i in range(3,x,2):
        if x % i != 0:
            result -=1
    if result == 0:
        print(x)
        break
    x=x+1

Submission status: Accepted

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

if x == 2:
  print(x)
  sys.exit()

for i in range(x,100005):
  flg = 0
  for j in range(2,int(math.sqrt(i))+1):
    if i%j == 0:
      flg = 1
    if flg == 0 and j == int(math.sqrt(i)):
      print(i)
      sys.exit()
    continue

Submission status: Accepted

Solution code:

# abc149_c

X = int(input())

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

if X==2:
  print(X)
else:
  p = False
  while not p:
    p = is_prime(X)
    if p:
      print(X)
    X = X+1

Submission status: Accepted

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

#####################################################################################

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################
def main():
    #CODE GOES HERE:
    x=ii()
    l=sieve(10**5 +4)
    for i in l:
        if i>=x:
            break
    print(i)
            

















    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

Solution code:
def primes(n,thr):
    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(thr, n + 1) if is_prime[i]]

def main():
    X = int(input())
    arr = primes(X+1000000, X)
    print(arr[0])

main()

Submission status: Accepted

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

    
    print(X)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import math

X = int(input())
count = 0
ok = 0
while ok == 0 :
    n = int(math.sqrt(X))
    for i in range(2,n+1) :
        if X % i != 0 :
            count += 1
    if count == n-1 :
        ok = 1
    else :
        X += 1
        count = 0
        
print(X)

Submission status: Accepted

Solution code:
# coding cell (SUBMIT ONLY THIS CELL)

import math

X = int(input())
temp = False

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

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

while temp == False:

    for i in range(int(math.sqrt(X) // 2)):
        if X % (2 * (i + 1) + 1) != 0:
            temp = True
        else:
            temp = False
            break

    X += 2        
    
print(X - 2)

Submission status: Accepted

Solution code:
# import sys
# sys.setrecursionlimit(10 ** 6)
# import bisect
# from decorator import stop_watch
# 
# 
# @stop_watch
def solve(X):
    primes = [2]
    ans = 2
    i = 1
    while True:
        i = i + 1
        if primes[-1] >= X:
            ans = primes[-1]
            break
        flg = True
        for p in primes:
            if p > i ** 0.5:
                break
            if i % p == 0:
                flg = False
                break
        if flg:
            primes.append(i)

    print(ans)


if __name__ == '__main__':
    X = int(input())
    solve(X)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
X = int(input())
a = 0
while(a==0):
    if X == 2:
        print(2)
        break
    for x in range(2,math.floor(math.sqrt(X))+1):
        if X % x == 0:
            break
        if x == math.floor(math.sqrt(X)):
            print(X)
            a = 1
    X += 1

Submission status: Accepted

Solution code:
from math import floor,sqrt
x = int(input())

if x==2 :
  print(2)
  exit()
elif x == 3:
  print(3)
  exit()
else:
  pass

while True:
  if all(x % i != 0 for i in range(2,int(floor(sqrt(x)))+1)) == True:
    print(x)
    exit()
  else:
    x += 1

Submission status: Accepted

Solution code:
X = int(input())

ans = -1
x = X
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:
def is_prime(n):
	# 対象の数(n)が素数かどうかを判定する	

	if n < 2:
		# 0,1 は素数ではない
		return False
	elif n == 2 or n == 3 or n == 5:
		return True
	elif n % 2 == 0 or n % 3 == 0 or n % 5 == 0:
		return False
	else:
		# nの平方根以下の素数候補ですべて試し割りする
		import math
		sqrt_ = math.floor(math.sqrt(n))
		
		primes = [7, 11, 13, 17, 19, 23, 29, 31]
		i = 0
			
		while True:
			for p in primes:
				if p + i <= sqrt_:
					if n % (p + i) == 0:
						return False
				else:
					return True
						
			i += 30


# C - Next Prime
x = int(input())

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

Submission status: Accepted

Solution code:
x = int(input())

n = 10**6
nums = [True]*(n+1)
nums[0] = nums[1] = False
for i in range(4, n+1, 2): nums[i] = False
for i in range(3, int(n**0.5)+1, 2):
  if nums[i]:
    for j in range(i+i, n, i):
      nums[j] = False

while True:
  if nums[x]:
    print(x)
    break
  x += 1

Submission status: Accepted

Solution code:
a = int(input())
from math import sqrt
M = 10**6
p = [1]*(M+1)
p[0] = p[1] = 0
for x in range(2, int(sqrt(M))+1):
    if p[x]:
        for y in range(x*x, M+1, x):
            p[y] = 0
for i in range(len(p)):
    if p[i] == 1 and i >= a:
        print(i)
        exit()

Submission status: Accepted

Solution code:
import math

x = int(input())

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

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

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

    return [prime for prime in primes if prime != 0]

nums = primes(199999)

for num in nums:
  if num >= x:
    print(num)
    break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# C - Next Prime
import math

def is_prime(n):
	# 対象の数(n)が素数かどうかを判定する	
	
	if n < 2:
		# 0,1 は素数ではない
		return False
	else:
		# nの平方根以下の数ですべて試し割りする
		sqrt_ = math.floor(math.sqrt(n))
		
		for i in range(2, sqrt_ + 1):
			if n % i == 0:
				return False
		
	return True


x = int(input())

while True:
	if is_prime(x):
		print(x)
		break
	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


x = int(input())

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

if x % 2 == 0:
    x += 1

while not is_prime(x):
    x += 2

print(x)

Submission status: Accepted

Solution code:
x = int(input())

def pcheck(n):
    for i in range(2, n):
        if n % i == 0:
            return True
    return False
while True:
    if pcheck(x) == False:
        a = x
        break
    else:
        x += 1

print(a)

Submission status: Accepted

Solution code:
# C
X=int(input())

def Primefact(n):
    Dic={}
    for i in range(2,int(pow(n,0.5))+1):
        if n%i==0:
            Dic[i]=0
            while True:
                n/=i
                Dic[i]+=1
                if n%i!=0:
                    break
        if n==1:
            break
    if n!=1:
        Dic[int(n)]=1
    return Dic

while True:
    D=Primefact(X)
    if len(D)==1:
        if X in D.keys():
            ans=X
            break
    X+=1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = int(input())

check = [True] * (pow(10, 5) + 1000)
check[0] = False
check[1] = False
N = len(check)

for i in range(2, N):
    if check[i]:
        cnt = 2
        st = i * cnt

        while st < N:
            check[st] = False

            cnt += 1
            st = i * cnt

for i in range(X, N):
    if check[i]:
        print(i)
        exit()

Submission status: Accepted

Solution code:
X=int(input())
if X==2:
  print(2)
else:
  for i in range(X,10**6):
    for j in range(2,i):
      if i%j==0:
        break
      if j==i-1:
        print(i)
        exit()

Submission status: Accepted

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

x=int(input())
flag=0
while True:
    for i in range(2,x//2):
        if x%i==0:
            flag+=1
    if flag==0:
        print(x)
        exit()
    flag=0
    x+=1