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: # AOJ 0044 Prime Number II
# Python3 2018.6.16 bal4u

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: import bisect
L = [True] * 60000
L[0] = L[1] = False

for i in range(2,int(60000**0.5)+1):
    if not L[i]:
        continue
    for j in range(i*2,60000, i):
        L[j] = False
p = [x for x in range(60000) if L[x]]
#print(" ".join(map(str,p)))
while True:
    try:
        n = int(input())
    except EOFError:
        break
    k = bisect.bisect_left(p,n)
    a = p[k-1]

    if p[k] == n:
        b = p[k+1]
    else:
        b = p[k]
    print(a,b)

Python: import math
import sys
isPrime=[False, False]
for i in range(2,1000000):
    isPrime.append(True)
for i in range(2,int(math.sqrt(1000000))):
    if isPrime[i]:
        for j in range(i*i, 1000000, i):
            isPrime[j]=False
for l in sys.stdin:
    f=int(l)
    ans=[]
    while True:
        if isPrime[f-1]:
            ans.append(int(f-1))
            break
        else:
            f=f-1
    f=int(l)
    while True:
        if isPrime[f+1]:
            ans.append(int(f+1))
            break
        else: 
            f=f+1
    print("%d %d"%(ans[0],ans[1]))

Python: import math

isPrime = [True] * 60001
primes = []
def eratos(n):
    isPrime[0] = isPrime[1] = False
    for i in range(2,int(math.sqrt(n))):
        if isPrime[i]:
            j = 2 * i
            while j <= n:
                isPrime[j] = False
                j = j + i
    for i in range(2,60000):
        if isPrime[i]:
            primes.append(i)
eratos(60000)

while True:
    try:
        p = int(input())
        min = list(filter(lambda x: x < p,primes))
        max = list(filter(lambda x: x > p,primes))
        print(min[-1],max[0])
    except:
        break

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

while True:
    try:
        n = int(input())
        i, a, b = 0, 0, 0
        while a == 0 or b == 0:
            i += 1
            if n - i - 1 >= 0 and a == 0 and c[n - i - 1] == 1:
                a = n - i
            if n + i - 1 < 50000 and b == 0 and c[n + i - 1] == 1:
                b = n + i
        print(a,b)
    except:
        break

Python: def main():
    is_prime = [i for i in range(1000000)]
    is_prime[0] = is_prime[1] = False

    for i in range(2, 1000000):
        is_prime[i] = True
    
    for i in range(2, 1000000):
        if i*i >= 1000000:
            break
        for j in range(i*i, 1000000, i):
            is_prime[j] = False
    
    while 1:
        try:
            ans = [0,0]
            n = int(input())
            for i in range(2,1000001):
                if is_prime[i]:
                    if i < n:
                        ans[0] = i
                    else:
                        if i != n:
                            ans[1] = i
                            break

            print('%s %d' % (ans[0],ans[1]))
        except:
            break

if __name__ == "__main__":
    main()

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

while True:
    try:
        n = int(input())
        i, a, b = 0, 0, 0
        while a == 0 and b == 0:
            i += 1
            if n - i >= 0 and a == 0 and c[n - i] == 1:
                a = n - i
            if n + i < 50000 and b == 0 and c[n + i] == 1:
                b = n + i
        print(a,b)
    except:
        break

Python: lst = [1]*50021
for i in range(50021):
    if i == 0:
        lst[i] = 0
    else:
        if lst[i] == 1:
            j = i +1
            k = i
            while True:
                k = k + j
                if k >= 50021:
                    break
                        
                lst[k] = 0

while True:
    try:
        n = int(input())
        a = lst[0:n-1]
        b = lst[n:]
        print((n - 1 - a[::-1].index(1)),(n + 1 + b.index(1)))

    except EOFError:
        break

Python: def make_ps(n):
    nums = [True for i in range(n)]
    nums[0] = nums[1] = False
    p = 2
    sqrt = n ** 0.5
    while p < sqrt:
        for i in range(2 * p, n, p):
            nums[i] = False
        while True:
            p += 1
            if nums[p]:
                break
    return [i for i in range(n) if nums[i]]
ps = make_ps(250)
def is_p(x):
    i = 0
    s = x ** 0.5
    while True:
        if ps[i] > s:
            break
        if not x % ps[i]:
            return False
        i += 1
    return True
while True:
    try:
        n = int(input())
    except:
        break
    for i in range(n - 1, 0, -1):
        if is_p(i):
            print(i, end=' ')
            break
    for i in range(n + 1, 50100):
        if is_p(i):
            print(i)
            break

Python: import sys
for e in sys.stdin:
 a=b=int(e)
 while 1:
  a-=1
  if 2 in[a,pow(2,a,a)]:break
 while 1:
  b+=1
  if 2 in[b,pow(2,b,b)]:break
 print(a,b)

Python: primes = [0, 0] + [1]*50020
for i in range(2, 226):
    if primes[i]:
        for j in range(i*i, 50021, i):
            primes[j] = 0

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

Python: import math
import os
import sys
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

def main():
    for Value in sys.stdin:
        value = int(Value)
        for v in range(0,value):
            if is_prime(v):
                prime_MAX = v
        for v in range(value+1,10000):
            if is_prime(v):
                break
        print(str(prime_MAX)+" "+str(v))        
if __name__ == '__main__':
    main()

Python: import sys
import math

primes = [2]
for line in sys.stdin:
  try:
    n = int(line)
    for i in range(max(primes) + 1, n):
      if i % 2 == 0:
        continue
      elif math.sqrt(i) == 0:
        continue
      elif len([j for j in primes if i % j == 0]) > 0:
        continue
      primes.append(i)
    for i in range(n - 1, 1, -1):
      if i % 2 == 0:
        continue
      elif math.sqrt(i) == 0:
        continue
      elif len([j for j in primes if i % j == 0 and i != j]) > 0:
        continue
      print(i, end=" ")
      break
    for i in range(n + 1, n + 10000):
      if i % 2 == 0:
        continue
      elif math.sqrt(i) == 0:
        continue
      elif len([j for j in primes if i % j == 0 and i != j]) > 0:
        continue
      print(i)
      break
  except:
    break