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())
if x==2:
    print(2)
else:   
    l=0
    a=[i for i in range(2,x)]
    prime=[]
    limit=math.sqrt(x)
    while True:
        p = a[0]
        if limit <= p:
            break
        prime.append(p)
        a = [e for e in a if e % p != 0]
    co=0
    x-=1
    l=len(prime)
    while co==0:
        c=0
        x+=1
        for i in range(l):
            if x%prime[i]!=0:
                c+=1
            else:
                break
        if c==l:
            print(x)
            co+=1

Submission status: Accepted

Solution code:
import math
from bisect import bisect_left


def eratosthenes(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]


def solve():
    X = int(input())
    primes = eratosthenes(100010)
    index = bisect_left(primes, X)
    print(primes[index])


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
# AtCoder Beginner Contest 149 : C (2019/12/29)
X = int(input())
if X != 2:
    if X % 2 == 0:
        X = X + 1
    while True:
        i = 2
        flag = False
        while True:
            if i >= X:
                flag = True
            if X % i == 0:
                break
            i = i + 1
        if flag == True:
            break
        else:
            X = X + 2
print(X)

Submission status: Accepted

Solution code:
import numpy as np
X = int(input())

v = np.arange(1, 100010)
a = np.zeros(v.shape[0], dtype='int')
a[0] += 1
for i in range(1, 318):
    # for i in range(X, 100010):
    a += (v % i == 0).astype('int')

a[:317] -= 1
prime = v[a == 1][1:]
print(prime[prime >= X][0])

Submission status: Accepted

Solution code:
X = int(input())

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

Submission status: Accepted

Solution code:
X = int(input())

def is_prim(n):
    i = 2
    while i*i <= n:
        if n%i == 0:
            return False
        i += 1
    return n != 1

for i in range(X, 10**9+1):
    if is_prim(i):
        print(i)
        break

Submission status: Accepted

Solution code:
X=int(input())

sosu=[1]*(10**5+4)
sosu[0]=0
sosu[1]=0
for i in range(2, 10**5+3):
  for j in range(i, 10**5+4-i, i):
    sosu[i+j]=0
    
print(X+sosu[X:].index(1))

Submission status: Accepted

Solution code:
x = int(input())

is_loop = True
while is_loop:
    is_prime = True
    for j in range(2, x):
        if x % j == 0:
            is_prime = False
            break
    if is_prime:
        is_loop = False
        print(x)
    x += 1

Submission status: Accepted

Solution code:
X = int(input())

import math
def using_sqrt(x):
    n = 0
    for k in range(x, 1000000):
        factor = 0

        # 2以外の偶数は素数ではないので無視する
        if k % 2 == 0 and k != 2:
            continue

        # 繰り返しの上限を対象の平方根にする
        for divisor in range(2, math.floor(math.sqrt(k)) + 1):
            if k % divisor == 0:
                factor += 1

        if factor == 0:
            #n += 1
            ans = k
            break

    return ans

ans = using_sqrt(X)
print(ans)

Submission status: Accepted

Solution code:
import sys

X = int(input())
x = X
while True:
    for i in range(2,x + 1):
        if i == x:
            print(x)
            sys.exit() 
        if (x % i) == 0 :
            break
    x += 1

Submission status: Accepted

Solution code:
MAX_SIZE = int(1e6) 


prime = [True] * (MAX_SIZE + 1) 

# coding seive
def seive(): 
	p = 2
	
	while (p * p <= MAX_SIZE): 
		
		if (prime[p] == True): 
			
		 for i in range(p * p, MAX_SIZE, p): 
				prime[i] = False
		p += 1

 
def Prime(n, k): 
	r = -1
	for i in range(n , MAX_SIZE): 
		
		
		if (prime[i] == True): 
			k -= 1
		
		if (k == 0): 
			r = i 
			break
	
	return r 
 
if __name__=='__main__': 
	n = int(input())
	k = 1
	seive() 
	
	
	print(Prime(n, k))

Submission status: Accepted

Solution code:
# C - Next Prime
X = int(input())
n = int(10**5)**2
def is_prime(n):
    for k in range(2, n):
        if n % k == 0:
            return False
        else:
            continue
    return True

if is_prime(X) == True:
    print(X)
else:
    for i in range(X+1,n+1):
        if is_prime(i) == True:
            print(i)
            exit()
        else:
            pass

Submission status: Accepted

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