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: Runtime Error

Solution code:
x= int(input())

def prime_check(num,count):
    if (num % count) != 0:
        if num <= count**2:
            return num
        else:
            return prime_check(num,count+1)
    else :
        return prime_check(num+1,2)

if x==2 :
    print (2)
else:
    prime_check(x,2)

Submission status: Runtime Error

Solution code:
# Original Submission At: https://atcoder.jp/contests/abc149/submissions/16823042
x= int(input())

def prime_check(num,count):
    while num % count == 0:
        num = num + 1
        count = 2
    if num <= count**2:
        print(num)
    else:
        prime_check(num,count+1)

if x==2 :
    print (2)
else:
    prime_check(x,2)

Submission status: Runtime Error

Solution code:
x= int(input())

def prime_check(num,count):
    if (num % count) != 0:
        if num <= count**2:
            print(num)
        else:
            prime_check(num,count+1)
    else :
        prime_check(num+1,2)

if x==2 :
    print (2)
else:
    prime_check(x,2)

Submission status: Runtime Error

Solution code:
x= int(input())

def prime_check(num,count):
    if (num % count) != 0:
        if num <= count**2:
            print(num)
        else:
            prime_check(num,count+1)
    else :
        prime_check(num+1,2)

prime_check(x,2)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
 
def p(x):
  if x == 2:
    return True
  for i in range(x//2):
    if x % i == 0:
      return False
  return True
 
for i in range(n,2*n):
  if p(i):
    print(i)
    break

Submission status: Runtime Error

Solution code:
n = int(input())
 
def p(x):
  if x == 2:
    return True
  for i in range(x/2):
    if x % i == 0:
      return False
  return True
 
for i in range(n,2*n):
  if p(i):
    print(i)
    break

Submission status: Runtime Error

Solution code:
n = int(input())

def p(x):
  if x == 2:
    return True
  for i in range(x/2):
    if x % i == 0:
      return False
  return True

for i in range(x,2*x):
  if p(i):
    print(i)
    break

Submission status: Runtime Error

Solution code:
X = int(input())
for i in range(X,120000):
  f = 0
  for j in range(2,math.ceil(math.sqrt(i))):
    if i % j == 0:
      f += 1
      break
  if f == 0:
    print(i)
    break

Submission status: Runtime Error

Solution code:
X = int(input())
for i in range(X+1, 9999999999999999):
    flag = 1
    for j in range(2, X//2 +1):
        if i % j == 0:
            flag = -1
            break
    # if X == 2:
    #     print(2)
    #     break
    # elif X == 3:
    #     print(3)
    #     break
    elif flag == 1:
        print(i)
        break

Submission status: Runtime Error

Solution code:
X = int(input())

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

for i in range(X+1, 2X+1):
  if is_Prime(i):
    print(i)
    break

Submission status: Runtime Error

Solution code:
a=int(input())
import math
for i in range(1,int(sqrt(a))):
  if a%i==0:
    a=a+1
  else:
    print(a)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
x = int(input())

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

Submission status: Runtime Error

Solution code:
x = int(input())
y = int(x**0.5)

while True:
  x % y != 0:
    y -=1
    if y !=1:
      x +=1
      continue
    elif y ==1:
      break
print(x)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
pip install sympy
from sympy import isprime

x = int(input())
if x % 2 == 0:
  x += 1

flag = True

while flag == True:
  if isprime(x) == True:
    flag = False

print(x)

Submission status: Runtime Error

Solution code:
from sympy import isprime

x = int(input())
if x % 2 == 0:
  x += 1

flag = True

while flag == True:
  if isprime(x) == True:
    flag = False

print(x)

Submission status: Runtime Error

Solution code:
import math
x=int(input())
def eratosthenes(n):
    """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]
ans=eratosthenes(10**5+3)
for i in  range(len(ans)):
	if ans[i]>=x:
    	print(ans[i])
	else:
      pass

Submission status: Runtime Error

Solution code:
#include<iostream>
using namespace std;

int prime(int n) {
	int i;

	if (n <= 1)/*1以下の場合は0を返す*/
	{
		return 0;/*素数ではない*/
	}
	/*nまでの数値を繰り返し、余りがあれば0を返す*/
	for (i = 2; i < n; i++) {
		if (n % i == 0) {
			return 0;/*素数ではない*/
		}
	}

	return 1;/*素数である*/
}

int main(){
  int x;
  cin>>x;
  int i=0;
  while(1){
    if (prime(x+i)==1){
      cout<<x+i<<endl;
      break;
    }
    else i++;
  }
}

Submission status: Runtime Error

Solution code:
import bisect
import math

prime = [i for i in range(2,10**5+1)]
for j in range(2, int(math.sqrt(10**5))):
    prime = [z for z in prime if (z == j) or (z % j != 0)]

a = int(input())

index = bisect.bisect_left(prime, a)

print(prime[index])

Submission status: Runtime Error

Solution code:
x=int(input())
from sympy import nextprime
print(nextprime(x))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from sympy import nextprime
n=int(input())
print(nextprime(n))

Submission status: Runtime Error

Solution code:
n=int(input())
for i in range(n,10**5):
  for j in range(2,10*5):
	if i%j==0:
      print(i)
      quit()

Submission status: Runtime Error

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

def is_prime(x):
    a = int(math.sqrt(X)) + 1#ある数が素数かどうかはO(√A)で判定できる
    for i in range(2,a):
        if x % i == 0:
            return False
    return True#xは素数

for j in range(X,10**5):
    if is_prime(j):
        ans = j    
        break
print(ans)

Submission status: Runtime Error

Solution code:
from sympy import sieve
x = int(input())
sosuu = list(sieve.primerange(2, 1000000))
for i in sosuu:
    if i >= x:
        print(i)
        break

Submission status: Runtime Error

Solution code:
x = int(input())
sosuu = list(sieve.primerange(2, 1000000))
for i in sosuu:
    if i >= x:
        print(i)
        break

Submission status: Runtime Error

Solution code:
import bisect
def seive():
  l[0]=0
  l[1]=0
  for i in range(2,10**5+1):
    if l[i]==1:
      k.append(i)
      for j in range(i*i,10**5+1,i):
        l[j]=0
l=[1]*(10**5+1)
k=[]
seive()
n=int(input())
d=bisect.bisect_left(k,n)
#print(d)
print(k[d])

Submission status: Runtime Error

Solution code:
import bisect
def seive():
  l[0]=0
  l[1]=0
  for i in range(2,10**5+1):
    if l[i]==1:
      k.append(i)
      for j in range(i*i,10**5+1,i):
        l[j]=0
l=[1]*(10**5+1)
k=[]
seive()
n=int(input())
d=bisect.bisect_right(k,n)
if k[d-1]>=n:
	print(k[d-1])
else:
  print(k[d])

Submission status: Runtime Error

Solution code:
from sys  import stdin,stdout

import bisect

import math

def st():
    return list(stdin.readline().strip())

def inp():
    return int(stdin.readline())

def li():
    return list(map(int,stdin.readline().split()))

def mp():
    return map(int,stdin.readline().split())

def pr(n):
    stdout.write(str(n)+"\n")

def soe(limit):
    l=[1]*(limit+1)
    prime=[]
    for i in range(2,limit+1):
        if l[i]:
            for j in range(i*i,limit+1,i):
                l[j]=0

    for i in range(2,limit+1):
        if l[i]:
            prime.append(i)
    return prime

def segsoe(low,high):
    limit=int(high**0.5)+1
    prime=soe(limit)
    n=high-low+1
    l=[0]*(n+1)
    for i in range(len(prime)):
        lowlimit=(low//prime[i])*prime[i]
        if lowlimit<low:
            lowlimit+=prime[i]
        if lowlimit==prime[i]:
            lowlimit+=prime[i]
        for j in range(lowlimit,high+1,prime[i]):
            l[j-low]=1
    for i in range(low,high+1):
        if not l[i-low]:
            if i!=1:
                print(i)

def power(a,n):
    r=1
    while n:
        if n&1:
            r=(r*a)
        a*=a
        n=n>>1
    return r

l=soe(10**5)

def solve():
    n=inp()
    a=bisect.bisect_left(l,n)
    print(l[a])



for _ in range(1):
    solve()

Submission status: Runtime Error

Solution code:
#
# 149C Next Prime
#
from sympy import nextprime

n = input()
print(nextprime(int(n)-1))