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:
from sympy import nextprime
n = int(input())
print(nextprime(n))

Submission status: Runtime Error

Solution code:
import math
x=int(input())
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: Runtime Error

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

Submission status: Runtime Error

Solution code:
# import math
import fractions

n = int(input())


def prime(n):
    if n == 1:
        n += 1
    while True:
        flag = 0
        for k in range(2, int(fractions.sqrt(n)) + 1):
            if n % k == 0:
                flag = 1
                break
        if flag == 0:
            return n
        n += 1


ans = prime(n)
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<vector>
#include<cmath>
//これ以上MAXを大きくできない…、スタックオーバーフロー
#define MAX 100100

using namespace std;

#if 1

bool isPrime(int n){
  if(n<=1) return false;
  int l=int(sqrt(n));
  for(int i=2;i<l+1;i++){
    if(n%i==0) return false;
  }
  return true;
}

#endif


int main(){
  int n;cin >> n;
  //エラトステネスの篩を実装する
  #if 1
  int N[MAX];//i番目が整数iに対応(1~100000)(1-オリジン)
  //0になったところは素数、1は素数ではない
  int l=int(sqrt(MAX));
  for(int i=2;i<l+1;i++){
    if(N[i]==0){
      for(int j=1;j<=floor((MAX)/i);j++){
        if(j!=1){
          N[j*i]=1;
        }
      }
    }
  }
  #endif
  for(int i=n;i<MAX;i++){
    if(N[i]==0){cout << i << endl;break;}
  }
}

Submission status: Runtime Error

Solution code:
x =  int(input())
 
def primes(z, n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if (is_prime[i]) and (i>=z) ]

Prime = primes(x, 10**5)
ans = Prime[0]
print(ans)

Submission status: Runtime Error

Solution code:
prime_list = [2]
for num in range(3,10**5,2):
    if all(num % prime != 0 for prime in prime_list):
        prime_list.append(num)
        if (num >= x):
            print(num)
            exit()
print(100003)

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
X = int(input())
import sympy
from sympy import nextprime
print(nextprime(X))

Submission status: Runtime Error

Solution code:
import fractions

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(fractions.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

X = int(input())

if is_prime(X):
    print(X)
    exit()
if X % 2 == 0:
    X += 1
while (1):
    if is_prime(X):
        print(X)
        break
    X += 2

Submission status: Runtime Error

Solution code:
import math
from bisect import bisect_left
from random import random


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

    d = (q - 1) >> 1
    while d & 1 == 0:
        d >>= 1

    for i in range(k):
        a = random.randint(1, q - 1)
        t = d
        y = pow(a, t, q)
        while t != q - 1 and y != 1 and y != q - 1:
            y = pow(y, 2, q)
            t <<= 1
        if y != q - 1 and t & 1 == 0:
            return False
    return True


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


if __name__ == '__main__':
    solve()

Submission status: Runtime Error

Solution code:
def isPrime(n):
  if n == 2:
    return True
  for p in range(2, n):
      if n % p == 0:
        return False
  return True

x = float(input())
while True:
  if isPrime(x):
    print(x)
    break
  x = x+1

Submission status: Runtime Error

Solution code:
import math
target = input()
def is_prime(n):
    for i in range(2, int(math.sqrt(n)) + 1):
        if n%i ==0:
            return False
    return True

not_found_flg = True
if target %2 == 0:
    target = target+1
result = 0
while not_found_flg:
    if (is_prime(target)):
        result = target
        break
    target = target+2

print(result)

Submission status: Runtime Error

Solution code:
X = int(input())
ret = X
while True:
    if(is_prime(ret)):
        print(ret)
        break
    else:
        ret += 1


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

Submission status: Runtime Error

Solution code:
x = int(input())
n = 10 ** 5
primes = set(range(2, n+1))
for i in range(2, int(n**0.5+1)):
    primes.difference_update(range(i*2, n+1, i))
primes = list(primes)
import bisect
b = bisect.bisect_right(primes, x)
print(primes[b])

Submission status: Runtime Error

Solution code:
def is_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

x = int(input())  
  
while not is_prime(x):
  x+=1
  
print(x)

Submission status: Runtime Error

Solution code:
import numpy

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(numpy.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

X = int(input())
result = 0
while result == 0:
    if is_prime(X):
        result = X
    else:
        X += 1
print(X)

Submission status: Runtime Error

Solution code:
import math
import bisect

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 

    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]

def is_prime(x):
    if x < 2: return False
    if x == 2 or x == 3 or x == 5: return True
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False

    
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True


if __name__ == '__main__':
    target = int(input())
    ps = primes(10**5+1)
    ans_idx = bisect.bisect_left(ps, target)
    print(ps[ans_idx])

Submission status: Runtime Error

Solution code:
x = int(input())
while True:
  if isPrime(x):
    print(x)
    break
  x = x+1
  
def isPrime(n):
  if n < 2:
    return False
  if n == 2:
    return True
  for p in range(2, n):
      if n % p == 0:
        return False
  return True

Submission status: Runtime Error

Solution code:
x =  int(input())

def primes(z, n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if (is_prime[i]) and (i>=z) ]

Prime = primes(x, 10**5)
ans = Prime[0]
print(ans)

Submission status: Runtime Error

Solution code:
from sympy import sieve
X = int(input())
a = 100004
b = [i for i in sieve.primerange(X,a)]
print(b[0])

Submission status: Runtime Error

Solution code:
from sympy import nextprime
N = int(input())
print(nextprime(N-1))

Submission status: Runtime Error

Solution code:
from sympy import sieve
 
def Eratosthenes(n):
    li = [i for i in range(2,n+1)]
    judge = [True for i in range(n+1)]
    ans = []
 
    for i in range(2,n+1):
        if judge[i] == True:
            for j in range(i*2,n+1,i):
                judge[j] = False
            ans.append(i)
    return ans
 
x = int(input())
l = Eratosthenes(10 ** 6)
for i in l:
    if i >= x:
        print(i)
        exit()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
primeN = []
for i in range(2, n):
    for j in range(2, i+1):
        if i % j == 0:
            if i == j:
                primeN.append(i)
            else:
                break
if primeN[-1]==n:
    print(n)
else:
    for d in range(n+1,9*n):
        for t in primeN:
            if d%t==0:
                print(d)
                break

Submission status: Runtime Error

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

x=int(readline())
def a(n):
  for i in range(2, int(n ** 0.5 + 1)):
    if n % i == 0:
      return False
  return True
  
  
n=x+1
while True:
  if a(n):
    pint(n)
    quit()
  n+=1

Submission status: Runtime Error

Solution code:
def is_prime2(q,k=100):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    for i in xrange(3,k):
        x,y = q,i
        while y:
            x, y =  y, x % y
        if x != 1: continue
        if pow(i, q-1, q) != 1:
            return False
    return True

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

Submission status: Runtime Error

Solution code:
def main():
    A, B, K = map(int, input().split())
    C = max(A - K , 0)
    K = max(K - A , 0)
    D = max(B - K , 0)
    print(C, D)



if __name__ == "__main__":
    main()