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 numpy as np
x = int(input())
def fp(a):
    if a == 1:
        return False
    for i in range(2,int(np.sqrt(a))+1):
        if a % i == 0:
            return False
    return True
for i in range(x,100004):
    if fp(i):
        print(i)
        exit()

Submission status: Accepted

Solution code:
def is_prime(n):
    p = 3
    while p * p <= n:
        if n % p == 0:
            return False
        else:
            p += 2
    return True


x = int(input())
if x == 2:
    print(x)
else:
    if x % 2 == 0:
        x += 1
    while True:
        if is_prime(x):
            print(x)
            break
        x += 2

Submission status: Accepted

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

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

for i in range(n,10**6):
	if check(i):
		print (i)
		exit()

Submission status: Accepted

Solution code:
import math

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]

a=primes(10**5+1000)
n=int(input())

for i in a:
    if n<=i:
        print(i)
        exit()

Submission status: Accepted

Solution code:
n=int(input())
e=10**5+10
sosu=[True for _ in range(e)]
for i in range(2,e):
    if i>=n and sosu[i]:
        print(i)
        exit()
    if sosu[i]:
        for j in range(i,e,i):
            sosu[j]=False

Submission status: Accepted

Solution code:
X = int(input())

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

prime = False
x = X

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
import math
X = int(input())
if X == 2:
    print(2)
else:
  x = math.ceil(math.sqrt(X))
  for i in range(X,X+1000):
      c = 0
      for j in range(2,x+1):
          if i % j == 0:
              c = 1
              break
      if c == 0:
          print(i)
          break

Submission status: Accepted

Solution code:
from sys import exit
from math import sqrt
X = int(input()) 
if X == 2: print(2)
elif X == 3: print(3)  
#elif X == 57: print(57)  
else:   
  for i in range(X,10**6):
    if i % 2 == 0: continue
    for j in range(3,X,2):
      if i % j == 0: break
      if j >= sqrt(i) :
        print(i)
        exit()

Submission status: Accepted

Solution code:
X = int(input())

check = 0
count = 0
while check == 0:
    check = 1
    number = X + count
    start = 2
    while check == 1 and start < number:
        if number % start == 0:
            check = 0
        start += 1
    count += 1

print(number)

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

n = int(input())

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

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def main():
    # input
    n = int(input().strip())
    l = list(range(2, 10**5+4))

    # main process
    for i in range(len(l)):
        l2 = []
        for j in range(len(l)):
            if l[j] % l[i] == 0 and l[j] != l[i]:
                pass
            else:
                l2.append(l[j])
        if len(l) == len(l2):
            break
        l = l2
        # eprint('l2 ', end=':\n')
        # eprint(l2)
    
    for i in range(len(l)):
        if l[i]>=n:
            print(l[i])
            return

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
x=int(input())
flag=False
flag2=True
if x==2:
  ans=2
  flag=True
if flag==False:
  if x%2==0:
    x+=1
  while 1:
    for i in range(3,int(x**0.5+1),2):
      #print("i",i,"x",x)
      if x%i==0:
        flag2=False
        break
    if flag2==True:
      ans=x
      break
    else:
      x+=2
      flag2=True
print(ans)

Submission status: Accepted

Solution code:



#約数リスト
import math
#素数列挙
def get_primes(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 resolve():
    n = int(input())
    A = get_primes(int(1.2*n))

    for i in A:
        if i>=n:
            print(i)
            return





if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import math
X = 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

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