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
X = int(input())
def is_prime(X):
  i = 2
  while i <= math.sqrt(X):
    if X % i == 0:
      return False
    i += 1
  return True
while not is_prime(X):
  X += 1
print(X)

Submission status: Accepted

Solution code:
x = int(input())
ans = x

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

Submission status: Accepted

Solution code:
import math

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

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

    return True
    
def main():
    X = int(input())
    
    flag = True
    while flag:
        if is_prime(X):
            flag = False
        else:
            X += 1
    print(X)


if __name__ == "__main__":
    main()

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

X = int(input())
flg = False

while flg!=True:
    flg = isprime(X)
    X = X + 1
print(X-1)

Submission status: Accepted

Solution code:
N = int(input())

if N%2==0 and not N==2:
    N=N+1

j = 0
while True:
    for i in range(2, N//2):
        if N%i==0:
            N += 2
            break
    else:
        break
print(N)

Submission status: Accepted

Solution code:
n = int(input())

c = 0

import math
def is_prime(a):
    if a == 1: return False

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

    return True

while(c == 0):
    if is_prime(n):
        print(n)
        break
    else:
        n += 1

Submission status: Accepted

Solution code:
N = int(input())

def ans(n):
    for i in range(2, N//2+1):
        if n%i==0:
            return ans(n+1)
    return n

print(ans(N))

Submission status: Accepted

Solution code:
import math
x = int(input())
plus = 1 if x % 2 == 0 else 2

class Prime:
    seed_primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

    def is_prime(self, n):
        """
        prime test (hybrid)

        see also: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """
        is_prime_common = self.is_prime_common(n)
        if is_prime_common is not None:
            return is_prime_common

        if n < 2000000:
            return self.is_prime_brute_force(n)
        else:
            return self.is_prime_miller_rabin(n)

    def is_prime_common(self, n):
        if n == 1: return False
        if n in Prime.seed_primes: return True
        if any(map(lambda x: n % x == 0, self.seed_primes)): return False

    def is_prime_brute_force(self, n):
        """
        brute force prime test
        use with is_prime_common if you want to skip seed_primes

        :param n:
        :return: boolean
        """
        for k in range(2, int(math.sqrt(n)) + 1):
            if n % k == 0:
                return False
        return True

    def is_prime_miller_rabin(self, n):
        """
        miller rabin prime test
        use with is_prime_common if you want to skip seed_primes

        see also
            algorithm: https://en.wikipedia.org/wiki/Miller%E2%80%93Rabin_primality_test
            implementation: https://qiita.com/srtk86/items/609737d50c9ef5f5dc59
            improvement: https://qiita.com/gushwell/items/ff9ed83ba55350aaa369

        :param n:
        :return: boolean
        """

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

        # use one of these lines / upper is more efficient.
        witnesses = self.get_witnesses(n)
        # witnesses = [random.randint(1, n - 1) for _ in range(100)]

        for w in witnesses:
            y = pow(w, d, n)

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

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

        return True

    def get_witnesses(self, num):
        def _get_range(num):
            if num < 2047:
                return 1
            if num < 1373653:
                return 2
            if num < 25326001:
                return 3
            if num < 3215031751:
                return 4
            if num < 2152302898747:
                return 5
            if num < 3474749660383:
                return 6
            if num < 341550071728321:
                return 7
            if num < 3825123056546413051:
                return 9
            return 12

        return self.seed_primes[:_get_range(num)]

    def gcd(self, a, b):
        if a < b:
            return self.gcd(b, a)
        if b == 0:
            return a
        while b:
            a, b = b, a % b
        return a

    @staticmethod
    def f(x, n, seed):
        """
        pseudo prime generator
        :param x:
        :param n:
        :param seed:
        :return: pseudo prime
        """
        p = Prime.seed_primes[seed % len(Prime.seed_primes)]
        return (p * x + seed) % n

    def find_factor(self, n, seed=1):
        """
        find one of factor of n
        this function is based to Pollard's rho algorithm

        see also
            algorithm: https://en.wikipedia.org/wiki/Pollard%27s_rho_algorithm
            implementation: https://qiita.com/gushwell/items/561afde2e00bf3380c98

        :param n:
        :param seed:
        :return: factor
        """
        if self.is_prime(n):
            return n

        x, y, d = 2, 2, 1
        count = 0
        while d == 1:
            count += 1
            x = self.f(x, n, seed)
            y = self.f(self.f(y, n, seed), n, seed)
            d = self.gcd(abs(x - y), n)

        if d == n:
            return self.find_factor(n, seed + 1)
        return self.find_factor(d)

    def find_factors(self, n):
        primes = {}
        if self.is_prime(n):
            primes[n] = 1
            return primes

        while n > 1:
            factor = self.find_factor(n)

            primes.setdefault(factor, 0)
            primes[factor] += 1

            n //= factor

        return primes

prime = Prime()
if prime.is_prime(x):
    print(x)
else:
    x += plus
    plus = 2
    while True:
        if prime.is_prime(x):
            break
        x += plus
    print(x)

Submission status: Accepted

Solution code:
import math
t=0
X=int(input())
while True:
  if X==2:
    break
  t=0
  for i in range(2,math.ceil((X)**(1/2))+1):
    if X%i==0:
      break
    else:
      t+=1
  if t==math.ceil((X)**(1/2))-1:
    break
  X+=1
print(X)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    print(find_next_prime(n))


def find_next_prime(n):
    return find_prime_in_range(n, 2*n)


def find_prime_in_range(a, b):
    for p in range(a, b):
        for i in range(2, p):
            if p % i == 0:
                break
        else:
            return p
    return None


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

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())

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

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 is_prime

n=int(input())
is_prime=primes(10**6)
for i in range(n,10**6):
    if is_prime[i]:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def is_prime(n):
    for p in range(2,n):
        if n % p ==0:
            return True

N =int(input())
p=N
while p <10**7:
    if is_prime(p):
        p +=1
    else:
        print(p)
        break

Submission status: Accepted

Solution code:
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

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

X = I()

while 1:
    flag = True
    for i in range(2,int(X**0.5+1)):
        if X%i==0:
            flag = False
            break
    if flag:
        break
    else:
        X += 1

print(X)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

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

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

Submission status: Accepted

Solution code:
n = int(input())
ma = 100003
prime = [True] * (ma + 1)
prime[0] = False
prime[1] = False
for i in range(2, int(ma ** 0.5) + 1):
    if not prime[i]:
        continue
    for j in range(i * 2, ma + 1, i):
        prime[j] = False
if prime[n]:
    print(n)
else:
    for i in range(n + 1, len(prime)):
        if prime[i]:
            print(i)
            break

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
X = int(input())

def primes(n):
    sieve = [True] * n
    for i in range(3,int(n**0.5)+1,2):
        if sieve[i]:
            sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)
    return [2] + [i for i in range(3,n,2) if sieve[i]]

pn = primes(10**6)

def bsearch(v, l, r):
    if l >= r - 1:
        return [l, r]
    m = l + ((r - l) // 2)
    if pn[m] < v:
        return bsearch(v, m, r)
    else:
        return bsearch(v, l, m)

l, r = bsearch(X, 0, len(pn))

if X == 2:
    print(2)
else:
    print(pn[r])

Submission status: Accepted

Solution code:
import unittest
import math


class TestC(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think(20), 23)

    def test_2(self):
        self.assertEqual(think(2), 2)

    def test_3(self):
        self.assertEqual(think(99992), 100003)


def solve():
    x = read()
    result = think(x)
    write(result)


def read():
    return read_int(1)[0]


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(x):
    index = 0
    while True:
        buf = x + index
        if is_prime(buf):
            return buf
        index += 1


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

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


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10000000)
# input = sys.stdin.readline
from bisect import *
# from collections import *
# from heapq import *
# import functools
# import itertools
# import math
INF = 500000
MOD = 10**9+7

ps = []
is_p = [True] * 10**6
for i in range(2, 10**6):
    if is_p[i]:
        for j in range(i+i, 10**6, i):
            is_p[j] = False
        ps.append(i)
# print(ps)
print(ps[bisect_left(ps, int(input()))])

Submission status: Accepted

Solution code:
def A():
    temp = input().split()
    print(''.join(temp[::-1]))

def B():
    temp = [int(n) for n in input().split()]
    A = temp[0]
    B = temp[1]
    K = temp[2]
    to_minus = min(A, K)
    A -= to_minus
    K -= to_minus
    if K > 0:
        B -= min(B, K)
    print (A, B)

import math
def C():
    X = int(input())
    if X <= 2:
        print(2)
        return

    def isPrime(n):
        if n <= 3:
            return True
        if(n % 2 == 0 or n % 3 == 0): 
            return False
      
        for i in range(5,int(math.sqrt(n) + 1), 6):  
            if(n%i == 0 or n%(i + 2) == 0): 
                return False
        
        return True
    
    while True:
        if isPrime(X):
            print(X)
            return
        X += 1

C()

Submission status: Accepted

Solution code:
from bisect import bisect_left
def prime(n):
    a = [0] * (n + 1)
    a[0] = 1
    a[1] = 1
    i = 2
    while n // i >= i:
        if a[i] != 0:
            i += 1
            continue
        j = 2 * i
        while j <= n:
            a[j] = 1
            j += i
        i += 1
    return [i for i, ai in enumerate(a) if ai == 0]


x = int(input())
primes = prime(10**6)
p = bisect_left(primes, x)
print(primes[p])

Submission status: Accepted

Solution code:
#  Copyright: this code was written at Dec 30th, 2019. for AtCoder, by Silviase
import math


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


n = int(input())
while not is_prime(n):
    n += 1
print(n)

Submission status: Accepted

Solution code:
import math
import sys

m=10**9 + 7 
sys.setrecursionlimit(1000010)
INF=10**9


[X]  = list(map(int,input().split()))
# print(X)

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


def primes(n):
    ass = []
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 2):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    for i in range(len(is_prime)):
        if is_prime[i]:
            ass.append(i)
    return ass

for i in range(X,INF):
    if is_prime(i):
        print(i)
        exit(0)
print(-1)

Submission status: Accepted

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

def 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
    
while not(prime(n)):
    n += 1

    
print(n)

Submission status: Accepted

Solution code:
x=int(input())
n=10**5 +10**4
flag=0
pn=0
if x==2:
    print(2)
else:
    for i in range(x,n):
        flag=0
        for k in range(2, int((i)**(1/2))+5):
            if i%k==0:
                flag+=1
        if flag==0:
            pn=i
            break
    print(pn)

Submission status: Accepted

Solution code:
def pm_table(n):
    """
    素数テーブル
    n以下の素数のリストを返却する
    :param n:
    :return:素数のリスト
    """
    res = [1] * (n + 1)
    res[:2] = 0, 0

    for i in range(2, n):
        if i ** 2 > n:
            break

        if res[i] == 1:
            for j in range(i * 2, n + 1, i):
                res[j] = 0

    return [i for i, x in enumerate(res) if x == 1]


X = int(input())
tbl = pm_table(10 ** 6)
for p in tbl:
    if X <= p:
        print(p)
        exit()

Submission status: Accepted

Solution code:
def check_primal(num):
    '''素数だったら0を、違ったら1を返す'''
    for mod in range(2, int(num**0.5+1)):
        if num % mod == 0:
            return 1
    return 0


x = int(input())

for i in range(x, 100004):
    if check_primal(i) == 0:
        print(i)
        break

Submission status: Accepted

Solution code:
def isPrime(n):
  for i in range(n):
    if i == 0 or i == 1:
      continue
    if n % i == 0:
      return False
  return True

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from subprocess import*
x=int(input())
while len(Popen(['factor',str(x)],stdout=PIPE).communicate()[0].split())>2:x+=1
print(x)

Submission status: Accepted

Solution code:
import bisect
sieve=[1]*1000001
i=2
while i*i<=1000001:
    if sieve[i]==1:
        for j in range(i*i,1000001,i):
            sieve[j]=0
    i+=1
lol=[]
for i in range(2,1000001):
    if sieve[i]:
        lol.append(i)
        
x=int(input())
y=bisect.bisect(lol,x)
if lol[y-1]==x:
    print(x)
else:    
    print(lol[y])

Submission status: Accepted

Solution code:
# coding: utf-8
def elatostenes(x):
    for i in range(2, int(x ** 0.5)+1):
        if x % i == 0:
            return False
    return True

X = int(input())
while True:
    if elatostenes(X):
        print(X)
        exit()
    else:
        X += 1

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

# エラストテネスの篩
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []
    time = 0

    while True:
        prime = min(A)

        if prime > math.sqrt(limit):
            break

        P.append(prime)

        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1

    for a in A:
        P.append(a)

    return P

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

  # ルジャンドル予想(未証明だが、、)
  # -> n^2 と (n+1)^2 の間に必ず素数が存在する
  # 10^(5/2) = 316.2277...
  # 317^2 = 100489
  P = eratosthenes(10**5+489)

  i = 0
  while True:
      if P[i] >= X:
          break
      i += 1

  print(P[i])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n = int(input())
c = n


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

X = int(input())
maxN = 10**5 + 1000
isPrime=[True]*(maxN+1)
isPrime[0],isPrime[1] = False,False

for i in range(2,maxN+1):
    if not(isPrime[i]):
        continue
    tmp = i*2
    while tmp<maxN:
        isPrime[tmp] = False
        tmp += i

ans = X
while not(isPrime[ans]):
    ans += 1
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def check(num):
  if num > 1:
    for i in range(2,num):
      if (num % i) == 0:
        return False
        break
    else:
      return True
  else:
    return False

a = int(input())
for i in range(a,100500):
  if check(i):
    print(i)
    break

Submission status: Accepted

Solution code:
x=int(input())
cont=0
for i in range(x,10**12):
    for j in range(2,i):
        if i%j==0:
            cont+=1
    if cont==0:
        print(i)
        exit()
    cont=0

Submission status: Accepted

Solution code:
import math
import bisect
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]
    return data

N=int(input())
L=get_sieve_of_eratosthenes(10**5+10)
print(L[bisect.bisect_left(L,N)])

Submission status: Accepted

Solution code:
x = int(input())

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

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

print(x)

Submission status: Accepted

Solution code:
def c_next_prime():
    from bisect import bisect_left
    X = int(input())

    def prime_table(n):
        """n以下の素数のリスト(エラトステネスの篩)"""
        is_prime = [True] * (n + 1)
        is_prime[0] = is_prime[1] = False  # 0と1は素数でない
        for j in range(2, int(n**0.5) + 1):
            if not is_prime[j]:
                continue
            for k in range(j * 2, n + 1, j):
                is_prime[k] = False  # jの倍数は素数でない
        return [i for i in range(n + 1) if is_prime[i]]

    primes = prime_table(min(2 * X, 10**5 + 3))
    return primes[bisect_left(primes, X)]

print(c_next_prime())

Submission status: Accepted

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

################ DANGER ################
test = ""
test = \
"""

"""
########################################
test = list(reversed(test.strip().splitlines()))
if test:
    def input2():
        return test.pop()
else:
    def input2():
        return input()
########################################  
        
n = int(input2())

def primes(n):
    ps = [2]
    for odd in range(3, n + 1, 2):
        for p in ps:
            if odd % p == 0:
                break
            if p ** 2 > odd:
                ps.append(odd)
                break
    return ps


def isprime(n):
    last = int(n**.5)
    for m in primes(last):
        if n % m == 0:
            return False
    return True


def nextprime(n):
    if n in primes(n):
        return n
    elif n == 1:
        return 2
    else:
        i = n
        while not isprime(i):
            i += 1
        return i


print(nextprime(n))

Submission status: Accepted

Solution code:
def check(num):
    if num > 1:
        for i in range(2, num):
            if (num % i) == 0:
                return False
                break
        else:
            return True
    else:
        return False


a = int(input())

for i in range(a, 100500):
    if check(i):
        print(i)
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

def solve():
	x = int(input())
	number = x
	while isPrime(number) != True:
		number += 1
	print(number)

solve()

Submission status: Accepted

Solution code:
x = int(input())

def is_prime(n):
    prime = not(False)
    for i in range(2, n):
        if n%i == 0:
            prime = not(True)
            break
    return prime

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

x = int(input())

def judge(p):
    j = True
    for i in range(2, int(p**0.5)):  #O(√p)
        if p%i == 0:
            j = False
            continue
    return(j)
   
c = False
while not c:
    c = judge(x) 
    x += 1
    
print(x - 1)

Submission status: Accepted

Solution code:
f=[True]*(10**5+10000)
f[0]=False
f[1]=False
for i in range(2,len(f)):
  if f[i]:
    for j in range(i*2,len(f),i):
      f[j]=False
for i in range(int(input()),len(f)):
  if f[i]:
    print(i)
    break

Submission status: Accepted

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

from collections import deque, defaultdict
import itertools as ite
import sys
import math
import decimal

sys.setrecursionlimit(1000000)

INF = 10 ** 18
MOD = 10 ** 9 + 7

X = input()

while True:
    i = 2
    flag = True
    while i * i <= X:
        if X % i == 0:
            flag = False
            break
        i += 1
    if flag:
        print X
        exit()
    else:
        X += 1

Submission status: Accepted

Solution code:
def primes(N):
    p = [False, False] + [True] * (N - 1)
    for i in range(2, int(N ** 0.5) + 1):
        if p[i]:
            for j in range(i * 2, N + 1, i):
                p[j] = False
    return p


N = int(input())
P = primes(N * 2)
print([i for i in range(N, N * 2) if P[i]][0])

Submission status: Accepted

Solution code:
def find_next_prime(x):
	while True:
		for i in range(x):
			if i+1 == 1: continue
			if x == (i+1): return x
			if x%(i+1) == 0: break
		x += 1

x = int(input())
print(find_next_prime(x))

Submission status: Accepted

Solution code:
def is_prime(n: int):
    """自然数nが素数であるかを判定する
    計算量: O(sqrt(N))
    """
    if n == 1:
        return False
    for k in range(2, int(n**0.5) + 1):
        if n % k == 0:
            return False
    return True


x = int(input())

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

Submission status: Accepted

Solution code:
import math

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

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

    return True


X = int(input())

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

print(ans)

Submission status: Accepted

Solution code:
def c_next_prime():
    from bisect import bisect_left
    X = int(input())

    def prime_table(n):
        """n以下の素数のリスト(エラトステネスの篩)"""
        is_prime = [True] * (n + 1)
        is_prime[0] = is_prime[1] = False  # 0と1は素数でない
        for j in range(2, int(n**0.5) + 1):
            if not is_prime[j]:
                continue
            for k in range(j * 2, n + 1, j):
                is_prime[k] = False  # jの倍数は素数でない
        return [i for i in range(n + 1) if is_prime[i]]

    primes = prime_table(2 * X)
    return primes[bisect_left(primes, X)]

print(c_next_prime())

Submission status: Accepted

Solution code:
X = int(input())
P = [True] * 100100
for i in range(2, 100100):
    if not P[i]:
        continue
    for j in range(i*2, 100100, i):
        P[j] = False
for i in range(X, 100100):
    if P[i]:
        print(i)
        break

Submission status: Accepted

Solution code:
import math
x = int(input())
if x == 2:
    print(2)
    exit()
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

if x %2 == 0:
    target = (x+1)
else:
    target = x
for i in range(target, 1000000):
    if is_prime(i) is True:
        print(i)
        exit()
    else:
        continue

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


def main():
    x = int(input())

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
l = [1]*100010
l[0] = 0
l[1] = 0
for i in range(2,10**5+10):
  if l[i]:
    for j in range(2*i,10**5+10,i):
      l[j] = 0
while not l[n]:
  n += 1
print(n)

Submission status: Accepted

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

X = int(input())
done = False
while not done:
    a = make_divisors(X)
    if len(a) == 2:
        done = True
        c = X
    else:
        X += 1
       

print(c)

Submission status: Accepted

Solution code:
X = int(input())

def is_prime_number(n):
    """
    >>> is_prime_number(1)
    False

    >>> is_prime_number(29)
    True

    >>> is_prime_number(30)
    False
    """
    import math
    if n == 1:
        return False

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

for i in range(X, 10**9):
    if is_prime_number(i):
        print(i)
        break

Submission status: Accepted

Solution code:
X = int(input())
ans = X

def check(X):
    for i in range(2,X//2):
        if X % i == 0:
            return True
    return False

while(check(ans)):
    ans += 1

print(ans)

Submission status: Accepted

Solution code:
import numpy as np
i8 = np.int64

maxnum = 110000
X = int(input())
a = np.zeros(maxnum, i8)

for i in range(2, 400):
    if a[i] == 0:
        j = i * 2
        while j < maxnum:
            a[j] = 1
            j += i
for i in range(X, maxnum):
    if a[i] == 0:
        print(i)
        exit(0)

Submission status: Accepted

Solution code:
#c
def sosu(num):
    flag=True
    for i in range(2,num):
        if num%i==0:
            flag=False
    return flag
x=int(input())
ans=0
cnt=0
while True:
    ans=x+cnt
    if sosu(ans):
        print(ans)
        break
    cnt+=1

Submission status: Accepted

Solution code:
X = int(input())
result = []
for i in range(X,X*2):
    for j in range (2,i):
        if (i % j) == 0:
            break
    else:
            result.append(i)
            a = i
            break
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
  
  
x = int(input())

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

Submission status: Accepted

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

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