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: Wrong Answer

Solution code:
import math

r = int(input())


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 range(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


if r == 0 or r == 1:
    print(2)
else:
    if r % 2 == 0:
        r += 1

    while True:
        if is_prime2(r):
            break
        r += 2

    print(r)

Submission status: Wrong Answer

Solution code:
X = int(input())
sosu = True

while(sosu):
    for i in range(2,X):
        if X%i == 0:
            break
        if i == X-1:
            sosu = False
    if sosu == False: break
    X += 1

print(X)

Submission status: Wrong Answer

Solution code:
def main():
    x = int(input())
    sosuu = [2]
    A = 200000
    if x == 2:
        print(2)
    else:
        for L in range(3, A, 2):
            for L2 in sosuu:
                if L % L2 == 0:
                    break
            else:
                sosuu.append(L)
                if L >= x:
                    print(L)
                    break

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def sosu(x):
    arr = factorization(x)
    if len(arr) == 1:
        return True
    else:
        return False

def solve(X: int):
    ans = 2
    for i in range(X, 10**5+4):
        if i % 2 == 0 and X != 2:
            continue
        if sosu(i):
            ans = i
            break

    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    solve(X)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
X = int(input())
#X = 99992
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

for i in range(X, 100004):
    if is_prime(i):
      print(i)
      exit()

Submission status: Wrong Answer

Solution code:
X = int(input())


def isPrime(n):
    if n % 2 == 0:
        return False
    for i in range(3, int(n ** 0.5) + 1, 2):
        if n % i == 0:
            return False
    return n != 1


for i in range(X):
    num = X + i
    if isPrime(num):
        break

print(num)

Submission status: Wrong Answer

Solution code:
# ABC149c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**6)

    # map(int,input().split())
    x = int(input())

    def prime_numbers(right):
        pn = [2]
        for L in range(3, right):
            chk = True
            for L2 in pn:
                if L % L2 == 0:
                    chk = False
            if chk == True:
                pn.append(L)
                if L >= x:
                    print(L)
                    exit(0)
        return pn

    l = prime_numbers(x*x)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import bisect
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

n = int(read())
n *= 10

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)

idx = bisect.bisect_left(primes, n //2)


print(primes[idx])

Submission status: Wrong Answer

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

X = int(input())
flg = False
count = X
while flg==False:
    flg = is_prime(count)

    if flg==True:
        break
    count = count + 1
print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())

L = [2, 3, 5, 7, 11, 13, 17]

i = 18

while True:
  f = True
  for j in L:
    if i % j == 0 : f = False
  if f:
    if i > N: break
    L.append(i)
  i += 1
print (i)

Submission status: Wrong Answer

Solution code:
X = int(input())

def sqrt(x):
    last_guess=x/2
    while True:
        guess=(last_guess+x/last_guess)/2
        if abs(guess-last_guess)<.000001:
            break
        last_guess=guess
    return guess

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

def next_prime(N): 
    if (N <= 1): 
        return 2
  
    prime = N 
    found = False
    while(not found): 
        prime = prime + 1
  
        if(is_prime(prime) == True): 
            found = True
  
    return prime 

print(next_prime(X))

Submission status: Wrong Answer

Solution code:
# import numpy as np
# import math
import sys
input = sys.stdin.readline

X = int(input())

if X == 2:
    print(X)
    sys.exit()

if X % 2 == 0:
    X += 1

while True:
    temp = pow(2,X-1,X)
    if temp == 1:
        break
    else:
        X += 2

print(X)

Submission status: Wrong Answer

Solution code:
def is_prime(q):
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1

a = int(input())

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

Submission status: Wrong Answer

Solution code:
a = int(input())
ans = 0
flag = True
i=2
while flag:
  if a%i==0:
    ans = a
    flag = False
  i+=1
print(ans)

Submission status: Wrong Answer

Solution code:
#coding:utf-8
import math
import collections

def prime():
    prime = [2, 3]
    for i in range(5, 5000, 2):
        flag = True
        for j in range(1, len(prime)):
            if prime[j] ** 2 > i:
                break
            if i % prime[j] == 0:
                flag = False
                break
        if flag:
            prime.append(i)
    return prime

if __name__ == "__main__":
    x = int(input())
    prime = prime()
    #print(prime)
    for num in prime:
        if int(num) >= x:
            print(num)
            break

Submission status: Wrong Answer

Solution code:
x = int(input())

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

i = x
while not is_prime(i):
    i += 1

print(i)