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:
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

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

Submission status: Wrong Answer

Solution code:
X = int(input())

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
n = int(input())
if n < 2:
    print(2)
    sys.exit(0)

def is_prime(val, primes):
    for p in primes:
        if val % p == 0:
            return False
    return True

primes = [2, 3]
k = 6
while primes[-1] < n:
    if is_prime(k-1, primes):
        primes.append(k-1)
    if is_prime(k+1, primes):
        primes.append(k+1)
    k += 6
print(primes[-1])

Submission status: Wrong Answer

Solution code:
def sieve(n):
    is_prime = [True for _ in range(n)]
    is_prime[0] = False

    for i in range(2, n+1):
        if is_prime[i-1]:
            j = 2 * i
            while j <= n:
                is_prime[j-1] = False
                j += i
    return is_prime
x=int(input())
ans=sieve(2*10**5)
for i in range(x,2*10**5):
    if ans[i]:
        print(i+1)
        exit()

Submission status: Wrong Answer

Solution code:
def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
INF = float("inf")

import math
import collections


def factorial(n):
    # 試し割りによる素因数分解
    prime_count = collections.Counter()

    for i in range(2, int(math.sqrt(n)) + 2):
        while n % i == 0:
            n /= i
            prime_count[i] += 1
    if n > 1:
        prime_count[int(n)] += 1

    return prime_count


def solve(X: int):

    for i in range(X, 2*X+100):
        c = factorial(i)
        if len(c) == 1:
            break
    print(i)

    return


def main():

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


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
x=int(input())+1
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
while 1:
  if is_prime(x):print(x);exit()
  x+=1

Submission status: Time Limit Exceeded

Solution code:
# -*- coding:utf-8 -*-
X = int(input())

sosu_list = [2]

for num in range(3,X+1,2):
    if all(num%sosu != 0 for sosu in sosu_list):
        sosu_list.append(num)

if X == sosu_list[-1]:
    print(X)
else:
    if X % 2 ==0:
        X+=1
    while True:
        if all(X%sosu != 0 for sosu in sosu_list):
            print(X)
            break
        X += 2

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

def prime_check(n):
    if n % 2 == 0:
        return False
    f = 3
    while f * f <= n:
        if n % f == 0:
            return False
        else:
            f += 2
    else:
        return True

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

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

Submission status: Time Limit Exceeded

Solution code:
def Eratosthenes(x):
    lis = [int(i) for i in range(2,x)]
    #print(lis)
    res = list()
    while lis:
        a = lis.pop(0)
        res.append(a)
        lis = [i for i in lis if i%a != 0]
        #print(lis)
    return res

N = int(input())
lis = Eratosthenes(N)

x = N
while True:
    if all(x%i != 0 for i in lis):
        print(x)
        break
    x += 1

Submission status: Time Limit Exceeded

Solution code:
# エラトステネスの篩
# https://qiita.com/takayg1/items/3769ab4cc62a231f4259

def eratosthenes_sieve(n):
    is_prime = [True]*(n + 1)
    is_prime[0] = is_prime[1] = False
    for p in range(2, n + 1):
        if is_prime[p]:
            for q in range(2*p, n + 1, p):
                is_prime[q] = False
    return is_prime

MAX_N=(10**6)
Primes = eratosthenes_sieve(MAX_N)

x = int(input())
while True:
    if Primes[x]:
        print(x)
        exit()

Submission status: Time Limit Exceeded

Solution code:
import math
n=int(input())
if n==2:
    print(n)
else:
    cost=0
    for i in range(n,10**6):
        for j in range(2,int(math.sqrt(i))+1):
            if i%j==0:
                cost+=1
        if cost==0:
            print(i)
            break

Submission status: Time Limit Exceeded

Solution code:
import math


def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    x = int(input().rstrip())

    def get_sieve_of_eratosthenes(n: int):
        candidate = [i for i in range(2, n + 1)]

        primes = []
        while len(candidate) > 0:
            prime = candidate[0]
            candidate = [num for num in candidate if num % prime != 0]
            primes.append(prime)
        return primes

    # xまでの素数
    primes = get_sieve_of_eratosthenes(x)

    ans = x
    if not x in primes:
        while True:
            if any([ans % prime == 0 for prime in primes]):
                ans += 1
                continue
            break

    print(ans)




if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
X = int(input())
prime = [2]
for i in range(3, 100004):
  for p in prime:
    is_prime = True
    if i % p == 0:
      is_prime = False
      break
  if is_prime: prime.append(i)

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

Submission status: Time Limit Exceeded

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

# C - Next Prime /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点: 300点

# 問題文
# X以上の素数のうち、最小のものを求めよ。

# 注記
# 素数とは、2以上の整数であって、1と自分自身を除くどの正の整数でも割り切れないようなもののことです。
# 例えば、2,3,5は素数ですが、4,6は素数ではありません。

# 制約
#     2≤X≤105
#     入力はすべて整数

# 入力
# 入力は以下の形式で標準入力から与えられる。
# X

# 出力
# X以上の素数のうち、最小のものを出力せよ。

# 入力例 1
# 20

# 出力例 1
# 23

# 20以上の素数のうち、最小のものは 23です。

# 入力例 2
# 2

# 出力例 2
# 2

# Xが素数である場合もあります。

# 入力例 3
# 99992

# 出力例 3
# 100003


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    # S = lines[0]
    X = int(lines[0])
    # N, M = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    prime_numbers = get_prime_numbers(100004)

    for prime_number in prime_numbers:
        if prime_number > X:
            return [prime_number]


# ☆e.g.3が2秒をちょっとだけ超えます。。。
def get_prime_numbers(n):
    lst = [2]
    for i in range(3, n+1):
        flag = False
        for item in lst:
            if i % item == 0:
                flag = True
                break
        if flag is False:
            lst.append(i)
    return lst


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['20']
        lines_export = [23]
    if pattern == 2:
        lines_input = ['2']
        lines_export = [2]
    if pattern == 3:
        lines_input = ['99992']
        lines_export = [100003]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

    for i in range(10**5):
        num = X + i
        list = get_sieve_of_eratosthenes(num)
        if num in list:
            print(num)
            exit()


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")
    data = [i for i in range(2, n + 1)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import math

x = int(input())

prms = []
n = 2
while True:
    is_prm = True
    for prm in prms:
        if n % prm == 0:
            is_prm = False
            break
    if is_prm:
        prms.append(n)
        if n >= x:
            break
    n += 1

print(n)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
#素数の列を、つ、つくるわよ
prime_list = [2]
for num in range(3, x + 1, 2):
  if all(num % prime != 0 for prime in prime_list):
    prime_list.append(num)

#xが素数である場合
if x == prime_list[-1]:
  print(x)
  exit()

#素数は奇数だけ
if x % 2 == 0:
  p = 1
else:
  p = 0
  
#xから、x未満の最大の素数ｘ２の範囲について調べるわ
#素数ｎ<素数ｍ<素数２ｎは常識？
for i in range(x - p, prime_list[-1] * 2 + 1, 2):
  if all(i % j != 0 for j in prime_list):
    print(i)
    exit()

Submission status: Time Limit Exceeded

Solution code:
X = int(input())

def prime_list(X):
    N = X
    flg = True
    while flg :
        for i in range(2,int(N**(1/2))+1):
            if N % i == 0:
                N = N + 1
                flg = True
                break
            else:
                flg = False
    return N



print(prime_list(X))

Submission status: Time Limit Exceeded

Solution code:
X=int(input())
num=10**5
ori_plist=[2]
i=3
while i<num:
    plist=ori_plist[:]
    for j in range(len(plist)):
        if i%plist[j]==0:
            i+=1
            break
    else:
        plist.append(i)
        i+=1
        ori_plist=plist[:]

if plist.count(X)==1:
    print(X)
    exit()
else:
    plist.append(X)
    ans=sorted(plist)
    a=ans.index(X)
print(ans[a+1])

Submission status: Time Limit Exceeded

Solution code:

a=int(input())
so=[]
def sosu(a):
    global so
    x=2
    while True:
        if all( x% elem != 0 for elem in so)==True:
            so.append(x)
            if x>=a:
                print(str(x))
                break
        x+=1

sosu(a)

Submission status: Time Limit Exceeded

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) == True:
        a = x
    else:
        x += 1

print(a)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

pl = [2]

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

cnt = 3
f = False

while True:
    if cnt == x:
        f = True
    for i in range(len(pl)):
        if cnt % pl[i] == 0:
            break
    else:
        pl.append(cnt)
        if f:
            print(cnt)
            exit()
    cnt += 1

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    X = int(input())
    ans = X
    while True:
        count = 0
        if X != 2 and X != 3 and X != 4 and X != 5 and X != 6:
            for i in range(7, X):
                if X%i == 0:
                    count += 1
            if count == 0:
                print(ans)
                exit()
            else:
                ans += 1
        elif X != 2:
            print("2")
        elif X != 3:
            print("3")
        elif X != 4 and X != 5:
            print("5")
        else:
            print("7")
resolve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

while True:
    if x % 2 == 0:
        x += 1
        continue
    i = 1
    while i * i <= x:
        if x % i == 0:
            break
        i += 1
    else:
        print(x)
        exit()
    x += 1

Submission status: Time Limit Exceeded

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

sosuu = [2]
A = 100000
for L in range(3, x+100, 2): # 2 以外の素数は奇数なので
    for L2 in sosuu:
        if L % L2 == 0:
            break # 素数でないことがわかったらそれ以上ループする必要はない
    else: # break で抜けることがなかったら L は素数（Python 特有の制御構文）
        sosuu.append(L)

for i in sosuu:
    if x<=i:
        print(i)
        sys.exit()

Submission status: Time Limit Exceeded

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

sosuu = [2]
A = 100000
for L in range(3, x+100, 2): # 2 以外の素数は奇数なので
    for L2 in sosuu:
        if L % L2 == 0:
            break # 素数でないことがわかったらそれ以上ループする必要はない
    else: # break で抜けることがなかったら L は素数（Python 特有の制御構文）
        sosuu.append(L)

for i in sosuu:
    if x<=i:
        print(i)
        sys.exit()

Submission status: Time Limit Exceeded

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

sosuu = [2]
A = 100000
for L in range(3, A, 2): # 2 以外の素数は奇数なので
    for L2 in sosuu:
        if L % L2 == 0:
            break # 素数でないことがわかったらそれ以上ループする必要はない
    else: # break で抜けることがなかったら L は素数（Python 特有の制御構文）
        sosuu.append(L)

for i in sosuu:
    if x<=i:
        print(i)
        sys.exit()

Submission status: Time Limit Exceeded

Solution code:
x=int(input())

sosuu = [2]
A = 100000
for L in range(3, A, 2): # 2 以外の素数は奇数なので
    for L2 in sosuu:
        if L % L2 == 0:
            break # 素数でないことがわかったらそれ以上ループする必要はない
    else: # break で抜けることがなかったら L は素数（Python 特有の制御構文）
        sosuu.append(L)
for i in sosuu:
    if x<=i:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
x=int(input())

sosuu=[2];A=100000
for L in range(3,A):
    chk=True
    for L2 in sosuu:
        if L%L2 == 0:chk=False
    if chk==True:sosuu.append(L)
for i in sosuu:
    if x<=i:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
x=int(input())

sosuu=[2];A=1000000
for L in range(3,A):
    chk=True
    for L2 in sosuu:
        if L%L2 == 0:chk=False
    if chk==True:sosuu.append(L)
for i in sosuu:
    if x<=i:
        print(i)
        break

Submission status: Time Limit Exceeded

Solution code:
def nprime(x):
  prim=[]
  i=1
  while(1):
    i+=1
    non=False
    for num in prim:
      if i%num==0:
        non=True
        break
    if non:
      continue
    elif(i>=x):
      return i
    prim.append(i)

print(nprime(int(input())))

Submission status: Time Limit Exceeded

Solution code:
x= int(input())
a = [2]
n = 2
while a[-1] < x:
    n += 1
    if all(n%i for i in a):
        a.append(n)
print(n)

Submission status: Time Limit Exceeded

Solution code:
X=int(input())
ps=[2]
x=2
while ps[-1]<X:
  f=True
  for p in ps:
    if x%p==0:
      f=False
      break
  if f:ps.append(x)
  x+=1
print(ps[-1])

Submission status: Time Limit Exceeded

Solution code:
from collections import deque

X = int(input())
nums = deque([i for i in range(3, 10**5+10, 2)])

prime = 2
while prime < X:
    prime = nums.popleft()
    nums = deque([i for i in nums if i % prime != 0])
print(prime)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
prime = []
for i in range(2, x):
  is_prime = True
  for j in prime:
    if i % j == 0:
      is_prime = False
      break
  if is_prime:
    prime.append(i)
i = x
while True:
  is_prime = True
  for j in prime:
    if i % j == 0:
      is_prime = False
      i += 1
      break
  if is_prime:
    print(i)
    break

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
X=int(input())
prime=[2]
for i in range(3,10**5+10**4):
  for k in prime:
    if i%k==0:
      break
    if k==prime[-1]:
      prime+=[i]
for i in prime:
  if i>=X:
    ans=i
    break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
def factors(n):
    return [i for i in range(2, n) if n % i == 0]


X = int(input())

prime_l = factors(X)
while True:
    for i in prime_l:
        if X % i == 0:
            break
    prime_l.append(X)
    X += 1
print(X)

Submission status: Time Limit Exceeded

Solution code:
def is_prime(n):
    if n < 2 or n&1 == 0:
        return False
    for i in range(2, n):
        if i*i > n or n % i == 0:
            return False
    return True


X = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
def get_prime_list(n):
    data = [i for i in range(2, n+100)]
    for d in data:
        data = [x for x in data if (x == d or x % d != 0)]
    return data


X = int(input())

data2 = get_prime_list(X)
for y in data2:
    if y >= X:
        print(y)
        break

Submission status: Time Limit Exceeded

Solution code:
def furui(n):
  data = [i for i in range(2, 2*n)]
  ans = []
  while True:
    sentou = data[0]
    if sentou >= n:
      return sentou
    ans.append(sentou)
    data = [i for i in data[1:] if i % sentou != 0]

x = int(input())
print(furui(x))

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
primes = [2]
if x != 2:
    for i in range(3, x, 2):
        prime_flg = True
        for num in primes:
            if i % num == 0:
                prime_flg = False
            else:
                pass
        if prime_flg == True:
            primes.append(i)
target = x
ans = 0
if x != 2:
    while(True):
        prime_flg = True
        for num in primes:
            if target % num == 0:
                prime_flg = False
            else:
                pass
        if prime_flg == True:
            ans = target
            break
        else:
            target += 1
else:
    ans = 2
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x=int(input())
N=1000003
primes=[i for i in range(2,N+1)]
p=min(primes)
seen=[]
while p<N**0.5:
    i=2
    while p*i<N:
        if p*i in primes:
            primes.remove(p*i)
        i+=1
    seen.append(p)
    for i in primes:
        if i not in seen:
            p=i
    
for i in range(len(primes)):
    if primes[i]>x:
        ans=i
        break
print(primes[i])

Submission status: Time Limit Exceeded

Solution code:

n = int(input())

pr = []
i = 2
while(True):
    for p in pr:
        if(i % p == 0):break
    else:
        if(i >= n):
            print(i)
            exit()
        pr.append(i)
    i += 1

Submission status: Time Limit Exceeded

Solution code:
prime=[2]
x=int(input())
for i in range(3,100005,2):
  for j in range(len(prime)):
    if i%prime[j]==0:
      break
  else:
    prime.append(i)

for i in range(len(prime)):
  if prime[i]>=x:
    print(prime[i])
    break

Submission status: Time Limit Exceeded

Solution code:
prime=[]
x=int(input())
for i in range(2,100005):
  for j in range(len(prime)):
    if i%prime[j]==0:
      break
  else:
    prime.append(i)

for i in range(len(prime)):
  if prime[i]>=x:
    print(prime[i])
    break

Submission status: Time Limit Exceeded

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

p = [2]
i = 1
Flag = True
if x > 2:
    while Flag:
        i += 2
        for j in p:
            if i%j == 0:
                break
            elif j == p[-1]:
                p.append(i)
                if i >= x:
                    ans = i
                    Flag = False

print(ans)

Submission status: Time Limit Exceeded

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

p = [2]
i = 3
while i < x:
    for j in p:
        if i%j == 0:
            break
        elif j == p[-1]:
            p.append(i)
    i += 2

if x > 2:
    flag = True
    while flag:
        for j in p:
            if i%j == 0:
                break
            elif j == p[-1]:
                ans = i
                flag = False
                break
        i += 2
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

if x == 2:
    print(2)
    quit()
li = [2]
for i in range(3, 10 ** 6, 2):
    for j in li:
        if i % j == 0:
            break
    else:
        if i >= x:
            print(i)
            quit()
        li.append(i)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import permutations as perm
from collections import deque, Counter as cnt
from collections import defaultdict as dd
from operator import itemgetter as ig
from bisect import bisect_right as bsr
from math import factorial, ceil, floor
import sys
sys.setrecursionlimit(1000000)

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)


def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]


def nlist(n, v):
    if not n:
        return [] if type(v) is list else v
    return [nlist(n[1:], v) for _ in range(n[0])]


def yesno(v, yes="Yes", no="No", upper=False):
    if upper:
        print([yes.upper(), no.upper()][not v])
    else:
        print([yes, no][not v])


def main():
    """エントリーポイント"""
    N = input(int)
    primes = [2]
    for x in range(3, 100000 + 100, 2):
        for p in primes:
            if x % p == 0:
                break
        else:
            primes.append(x)
    for p in primes:
        if N <= p:
            print(p)
            break


if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

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

while (1):
  if prime(x)==False: x += 1
  else: break
  x += 1
print(x)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())

if x == 1:
    ans = 1
elif x == 2:
    ans = 2
else:    
    num = [3]
    for i in range(3, x, 2):
        for j in num:
            if (i % j) == 0:
                break
        else:
            num.append(i)
    last_num = i
    k = i + 1
    while True:
        for j in num:
            if (k % j) == 0:
                k += 1
                break
        else:
            ans = k
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
x = int(input())
prime_list = []
for n in range(2, x * 2):
  is_prime = True
  for m in prime_list:
    if n % m == 0:
      is_prime = False
      break
  if is_prime:
    if x <= n:
      print(n)
      exit(0)
    prime_list.append(n)