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:
import numpy as np
import math
from collections import Counter

def cumsum(x):
    return list(np.cumsum(x))

def cumsum_number(N,K,x):
    ans=[0]*(N-K+1)
    number_cumsum = cumsum(x)
    number_cumsum.insert(0,0)
    for i in range(N-K+1):
        ans[i]=number_cumsum[i+K]-number_cumsum[i]
    return ans
"""
int #整数
float #小数

#リスト
list0 = [0]*10 #[0,0,0,0,0,0,0,0,0,0]
list1= [i for i in range(10)] #>>> [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
number=[int(input()) for i in range(int(input()))] #複数行の入力をリストに
list1 = list1 + [6, 7, 8] #リストの追加
list2.append(34) #リストの追加　最後に（）内が足される
list.insert(3,10) #リストの追加　任意の位置（追加したい位置,追加したい値）
list5.count(2) #リスト(文字列も可）内の2の数
list1.sort() #並び替え小さい順
list1.sort(reverse=True)  #並び替え大きい順
set(list1) #list1内の重複している要素を削除し、小さい順に並べる

number=Counter(list) #listを値（文字）ごとにカウントし辞書型で返す [1:4,2:5 …]

text1 = text1.replace("34","test") #text1内の"34"を"test"に書き換える(文字列内の文字を入れ替える)
sorted(S) #Sを辞書順にソート
exit(0) #強制終了

cumsum(リスト) #累積和をリストで返す
cumsum_number(N,K,x) #N個の数が含まれるリストx内のK個からなる部分和をリストで返す

alphabet={0:"A",1:"B",2:"C",3:"D",4:"E",5:"F",6:"G",7:"H",8:"I",9:"J",
          10:"K",11:"L",12:"M",13:"N",14:"O",15:"P",16:"Q",17:"R",18:"S",19:"T",
          20:"U",21:"V",22:"W",23:"X",24:"Y",25:"Z",}
print(*S,sep="") #リストSを1つずつ出力

math.floor() #切り捨て
math.ceil() #切り上げ
"""
def prime(n):
    limit = math.floor(math.sqrt(n))
    for i in range(2,limit+1):
        if n % i == 0:
            return prime(n+1)
    return n

X = int(input())

print(prime(X))

Submission status: Runtime Error

Solution code:
def prime(n):
    limit = math.floor(math.sqrt(n))
    for i in range(2,limit+1):
        if n % i == 0:
            return prime(n+1)
    return n

X = int(input())

print(prime(X))

Submission status: Runtime Error

Solution code:
import math
s = int(input())
for i in range(s,2*s):
  if i%2==0:
    continue
  for k in range(3,round(math.sqrt(s))+1,2):
    t = 1
    if i%k ==0:
      t = 0
      break
  if t ==1:
    print(i)
    break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def eratosthenes(n):
    A = [i for i in range(2, n+1)]
    P = []
    i = 2
    while i**2 <= n:
        prime = min(A)
        P.append(prime)
        j = 0
        while j < len(A):
            if A[j] % prime == 0:
                A.pop(j)
                continue
            j += 1
        i += 1    
    for a in A:
        P.append(a)
    return P
    
x = int(input())
prime_table = eratosthenes(100003)
prime_set = set(prime_table)
if x in prime_set:
    print(x)
else:
    idx = bisect_right(prime_table, x)
    ans = prime_table[idx]
    print(ans)

Submission status: Runtime Error

Solution code:
from bisect import bisect_right

def eratosthenes(n):
    A = [i for i in range(2, n+1)]
    P = []
    i = 2
    while i**2 <= n:
        prime = min(A)
        P.append(prime)
        j = 0
        while j < len(A):
            if A[j] % prime == 0:
                A.pop(j)
                continue
            j += 1
        i += 1    
    for a in A:
        P.append(a)
    return P
    
x = int(input())
prime_table = eratosthenes(100003)
prime_set = set(prime_table)
if x in prime_set:
    print(x)
else:
    idx = bisect_left(prime_table, x)
    ans = prime_table[idx]
    print(ans)

Submission status: Runtime Error

Solution code:
# 21
import sympy
x = int(input())

#エラトステネスの篩
n = [i for i in range(2,int(sympy.sqrt(x))+1)]

for i in n:
    for j in n:
        if j % i == 0 and j/i !=1:
            n.remove(j)
            
while x > 0:
    x +=1
    for i in n:
        if x % i == 0:
            break
    else:
        print(x)
        break

Submission status: Runtime Error

Solution code:
## 21
import sympy
x = int(input())

#エラトステネスの篩
n = [i for i in range(2,int(sympy.sqrt(x))+1)]

for i in n:
    for j in n:
        if j % i == 0 and j/i !=1:
            n.remove(j)
            
while x > 0:
    x +=1
    for i in n:
        if x % i == 0:
            break
    else:
        print(x)
        break

Submission status: Runtime Error

Solution code:
from sympy import sieve

x = int(input())

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int X;
    cin >> X;

    for (int ans = X; ans <= int(1e9); ++ans) {
        bool ng = false;
        // cout << ans << endl;

        for (int i = 2; i <= int(sqrt(X)); ++i) {
            if (ans%i == 0) {
                ng = true;
                break;
            }
        }
        if (ng == false) {
            cout << ans << endl;
            break;
        }
    }

    return 0;
}

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using ull = unsigned long long;
using ll = long long;
using namespace std;

int main(void) {
    int X;
    cin >> X;

    for (int ans = X; ans <= int(1e9); ++ans) {
        bool ng = false;
        for (int i = 2; i <= int(sqrt(X)); ++i) {
            if (X%i == 0) {
                ng = true;
                break;
            }
        }
        if (ng == false) {
            cout << ans << endl;
            break;
        }
    }

    return 0;
}

Submission status: Runtime Error

Solution code:
def SieveOfEratosthenes(n): 
    prime = [True for i in range(10**5 + 1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * 2, 10**5 + 1, p): 
                if prime[i]:
                    prime[i] = False
        p += 1
    prime[0], prime[1]= False, False
    count = 1
    while(True):
        if prime[p] and p>n:
            print(p)
            break
        p += 1
            
n = int(input())
SieveOfEratosthenes(n)

Submission status: Runtime Error

Solution code:
def SieveOfEratosthenes(n): 
    prime = [True for i in range(10**5 + 1)] 
    p = 2
    while (p * p <= n): 
        if (prime[p] == True): 
            for i in range(p * 2, 10**5 + 1, p): 
                if prime[i]:
                    prime[i] = False
        p += 1
    prime[0], prime[1]= False, False
    count = 1
    while(True):
        if prime[p] and p>n:
            print(p)
            break
        p += 1
            
x = int(input())
SieveOfEratosthenes(n)

Submission status: Runtime Error

Solution code:
from sympy import isprime
X = int(input())
ans = 0
for i in range(X, 10 ** 5 + 1):
    if isprime(i):
        ans = i
        break

print(i)

Submission status: Runtime Error

Solution code:
X = int(input())
i = int(n**0.5)

while i >= 2:
    if X % i == 0:
        X += 1
        i = int(X**0.5)
    else:
        i -= 1
        
print(X)

Submission status: Runtime Error

Solution code:
x=int(input())

l=[]
for i in range(x,100000):
    if 0 not in [i%j for j in range(2,int(int(i)**1/2)+1)]:
        l.append(i)

print(l[0])

Submission status: Runtime Error

Solution code:
X = int(input())

c = [2,3,5]
if X <= 2:
    print(X)
for i in range(X, 10**5):
    if i % 2 != 0 and i % 3 != 0 and i % 5 != 0:
        break
print(i)

Submission status: Runtime Error

Solution code:
import math

x = int(input())

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

#2以外の素数は奇数であることに注意

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

Submission status: Runtime Error

Solution code:
a = int(input())

def factorization(n):
    arr = []
    tmp = n

    for i in range(2, int(n**0.5//1)+1):
        if tmp%i==0:
            cnt = 0
            while tmp%i==0:
                cnt+=1
                tmp//=i
            arr.append([i,cnt])
    if tmp!=1:
        arr.append([tmp,1])
    if arr==[]:
        arr.append([n,1])
    return arr

while True:
  arr = factorization(a)
  if (len(arr)==1) & (arr[1]==1):
    print(a)
    break
  a+=1

Submission status: Runtime Error

Solution code:
from sympy import isprime
n = int(input())
if isprime(n) == True:
    print(n)
else:
    print(sympy.nextprime(n))