Go: package main

import (
    "fmt"
    "bufio"
    "os"
    "strconv"
)

const MAX = 60000
const ROOT = 250

var sc =  bufio.NewScanner(os.Stdin)

func main() {
    var isPrime [MAX]bool
    for i := 2;i < MAX; i++ {
        isPrime[i] = true
    }
    for i := 2;i < ROOT; i++ {
        if isPrime[i] {
            for j := i * i;j < MAX; j+=i {
                isPrime[j] = false
            }
        }
    }
    var minPrime [MAX]int
    var maxPrime [MAX]int
    min := -1
    for i := 0;i < MAX; i++ {
        minPrime[i] = min
        if isPrime[i] {
            min = i
        }
    }
    max := -1
    for i := MAX - 1; i >= 0; i-- {
        maxPrime[i] = max
        if isPrime[i] {
            max = i
        }
    }

    for sc.Scan() {
        n, _ := strconv.Atoi(sc.Text())
        fmt.Printf("%d %d\n", minPrime[n], maxPrime[n])
    }
}

Python: # 04.77 sec -> Time Limit Exceeded?
import sys
import math

# Sieve of Eratosthenes
N = 50021
searchList = list(range(3, N + 1, 2))
primes = [2]
while True:
  top = searchList.pop(0)
  primes.append(top)
  if top > math.sqrt(N):
    break
  searchList = [s for s in searchList if s % top != 0]
primes.extend(searchList)

# solve
for line in sys.stdin:
  try:
    n = int(line)
    pre = 2
    for p in primes:
      if p < n:
        pre = p
      if p > n:
        print(pre, p)
        break
  except:
    break

Python: N = 50050
a = [True] *  N
i = 3
while i * i < N:
    for j in range(3 * i, N, 2 * i): a[j] = False
    i += 2
  
while True:
    try:
        n = int(input())
    except:
        break
 
    n0 = n + 2 if (n & 1) else n + 1
    for max in range(n0, N, 2):
        if a[max]: break
    n0 = n - 2 if (n & 1) else n - 1
    for min in range(n0, 2, -2):
        if a[min]: break
    else:
        min = 2
 
    print(min, max)

Python: def sieve(n):
	p=[True]*(n+1)
	p[0]=p[1]=False
	for i in range(2,int((n+1)*0.5)+1):
		if p[i]==True:
			for j in range(i*i,n+1,i):
				p[j]=False
	prime=[]
	for i in range(n+1):
		if p[i]==True:
			prime.append(i)
	return prime

def solve(n):
	i=0
	while True:
		if n>prime[i]:
			a=prime[i]
		elif n==prime[i]:
			a=prime[i-1]
		else:
			b=prime[i]
			break
		i+=1
	print(a,b)

prime=sieve(5003)
while True:
	try:
		n=int(input())
		solve(n)
	except EOFError:
		break

Python: import sys

def inp():
    for line in sys.stdin:
        i = 1
        while True:
            if is_prime(int(line[:-1]) - i) == True:
                print (int(line[:-1]) - i),
                break
            else:
                i += 1
        i = 1
        while True:
            if is_prime(int(line[:-1]) + i) == True:
                print (int(line[:-1]) + i)
                break
            else:
                i += 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
             
if __name__ == "__main__":
    inp()

Python: import bisect

MAX = 60000

#エラトステネスの篩
is_prime = [True for _ in range(MAX)]
is_prime[0] = is_prime[1] = False
for i in range(2, int(MAX ** (1 / 2)) + 1):
  if is_prime[i]:
    for j in range(i ** 2, MAX, i):
      is_prime[j] = False

primes = [i for i in range(MAX) if is_prime[i]]

while True:
  try:
    n = int(input())
    ind = bisect.bisect_left(primes, n)
    if primes[ind] == n:
      print(primes[ind - 1], primes[ind + 1])
    else:
      print(primes[ind], primes[ind + 1])

  except EOFError:
    break

Python: # -*- coding: utf-8 -*-

import sys
import os
import math
import itertools

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 s in sys.stdin:
    n = int(s)

    for i in range(n-1, 3, -1):
        if is_prime(i):
            answer0 = i
            break

    for i in range(n+1, 100000, 1):
        if is_prime(i):
            answer1 = i
            break

    print(answer0, answer1)

Python: pr=[True]*50100
for i in range(2,225):
    if pr[i]:
        for j in range(i*2,50100,i):
            pr[j]=False

while True:
    try:
        n=int(input())
    except:
        break
    for i in range(n-1,0,-1):
        if pr[i]:
            print(i,end=" ")
            break
    for i in range(n+1,50100):
        if pr[i]:
            print(i)
            break

Python: l = [2]
for i in range(3, 60000):
    flag = True
    for j in l:
        if i % j == 0:
            flag = False
            break
    if flag:
        l.append(i)

while True:
    try:
        n = int(input())
    except:
        break
    a = b = 0
    for k in range(1, n):
        if n -k in l:
            a = n-k
            break
    for kk in range(1, 10000):
        if n+kk in l:
            b=n+kk
            break
    print(a,b)

Python: from itertools import takewhile, dropwhile
pn, tmp = [], [i for i in range(2, 50000)]
while tmp[0] < 224:
    v = tmp.pop(0)
    pn.append(v)
    tmp = list(filter(lambda x: x%v!=0, tmp))
for t in tmp: pn.append(t)
while True:
    try:
        n = int(input())
    except:
        break
    print(list(takewhile(lambda x: x<n, pn))[-1], list(dropwhile(lambda x: x<=n, pn))[0])

Python: isPrime = [True] * 50100
prime = []
def calcPrime():
    isPrime[0] = isPrime[1] = False
    for i in range(len(isPrime)):
        if(isPrime[i]):
            prime.append(i)
            for j in range(2 * i, len(isPrime), i):
                isPrime[j] = False

calcPrime()
while(True):
    try:
        n = input()
        pos = 0
        while(prime[pos] < n):
            pos += 1
        print(prime[pos - 1]),
        if(n == prime[pos]):
            print(prime[pos + 1])
        else:
            print(prime[pos])
    except Exception:
        break

Python: # Aizu Problem 0009: Prime Number
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def primes2(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
        sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

primes = primes2(50500)

for line in sys.stdin:
    n = int(line)
    if n in primes:
        idx = primes.index(n)
        print(primes[idx-1], primes[idx+1])
    else:
        idx = bisect.bisect_right(primes, n)
        print(primes[idx-1], primes[idx])

Python: MAX = 50025
SQRT = 223     # sqrt(MAX)
 
prime = [True for i in range(MAX)]
def sieve():
    for i in range(4, MAX, 2):
        prime[i] = False
    for i in range(3, SQRT, 2):
        if prime[i] is True:
            for j in range(i*i, MAX, i):
                prime[j] = False
sieve()
 
while True:
    try:
        n = int(input())
    except EOFError:
        break
         
    for i in range(n-1, 1, -1):
        if prime[i]:
            a = i
            break
    for i in range(n+1, MAX):
        if prime[i]:
            b = i
            break   
    print(a, b)

Python: n = 50000
c = [1 for i in range(n)]
c[0] = 0
i = 2
while i**2 <= n:
    j = i*2
    while j <= n:
        c[j - 1] = 0
        j += i
    i += 1

c2 = []
for i in range(50000):
    if c[i] == 1:
        c2.append(i + 1)

while True:
    try:
        n = int(input())
        n_ind = c2.index(n)
        print(c2[n_ind - 1], c2[n_ind + 1])
    except:
        break