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: 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 - 1], primes[ind])

  except EOFError:
    break

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())
        print(list(takewhile(lambda x: x<n, pn))[-1], list(dropwhile(lambda x: x<=n, pn))[0])
    except:
        break

Python: import math
p = [2]
s = 3
max = 50000

while p[len(p)-1] <= max:
    m = int(math.sqrt(s))
    r = True
    for i in p:
        if i > m:
            break
        if s % i == 0:
            r = False
            break
    if r:
        p.append(s)
    s += 2

while True:
    try:
        n = int(raw_input())
    except EOFError as e:
        break
    i = 0
    while p[i] < n:
        i += 1
    print("%d %d" % (p[i-1], p[i+1] if p[i] == n else p[i]))

Python: 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():
    while True:
        try:
            value = int(input())
            prime_MAX = 0
            for v in range(2,value-1):
                if is_prime(v):
                    prime_MAX = v
            for v in range(value+1,50000):
                if is_prime(v):
                    break
            print(str(prime_MAX)+" "+str(v))        
        except EOFError:
            break

if __name__ == '__main__':
    main()

Python: def is_prime(x):
    if x <= 1:
        return False
    i = 2
    while i * i <= x:
        if x % i == 0:
            return False
        i += 1
    return True

while True:
    try:
        N = int(input())
    except EOFError:
        break
    mx = 0
    mn = 0
    for i in range(N - 1,1,-1):
        if is_prime(i):
            mx = i
            break
    for i in range(N + 1,N * 2):
        if is_prime(i):
            mn = i
            break
    print(mx,mn)

Python: import sys

def primegen():
  l = [2]
  while True:
    yield max(l)
    n = max(l)
    while True:
      n += 1
      flag = 1
      for i in l:
        if n % i == 0:
          flag = 0
          break
      if flag:
        l.append(n)
        break

for line in sys.stdin:
  n = int(line)
  seq = primegen()
  i1 = 0
  i2 = 0
  while i2 < n:
    i1 = i2
    i2 = seq.__next__()
  if i2 == n:
    i2 = seq.__next__()
  print(str(i1) + " " + str(i2))

Python: N = 50030
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 maxv in range(n0, N, 2):
        if a[maxv]: break
    n0 = n - 2 if (n & 1) else n - 1
    for minv in range(n0, 2, -2):
        if a[minv]: break
    else:
        minv = 2

    print(minv, maxv)

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, 0, -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: n = 50021
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 < 50021 and b == 0 and c[n + i - 1] == 1:
                b = n + i
        print(a,b)
    except:
        break

Python: n=1000000
p=[1]*(n+1)
p[0],p[1]=0,0
for i in range(2,int(n**0.5)+1):
    if p[i]:        
        for j in range(i*i,n+1,i):
            p[j]=0
p=[i for i in range(n+1) if p[i]==1]
while 1:
    try:n=int(input())
    except:break
    for i in range(len(p)):
        if p[i]==n:
            print(p[i-1],p[i+1])
            break 
        elif p[i]>n:
            print(p[i-1],p[i])
            break

Python: from itertools import chain
from bisect import bisect_left

max_n = 50022
primes = {2,3} | {m for n in (5, 7) for m in range(n, max_n, 6)}
du = primes.difference_update
for n in chain(range(5, max_n, 6), range(7, max_n, 6)):
    if n in primes:
        du(range(n*3, max_n, n*2))

primes = tuple(primes)

try:
    while True:
        n = int(input())
        i = bisect_left(primes, n)
        print(primes[i-1], primes[i+(n==primes[i])])
except EOFError:
    exit()

Python: def f(s,p):
    p.append(s.pop(0))
    for i,num in enumerate(s):
        if num % p[-1] == 0:
            s.pop(i)
    return 0

def vol44(k):
    for i in range(len(p)):
        if p[i] == k:
            print(p[i-1],p[i+1])
            break
        elif p[i] > k:
            print(p[i-1],p[i])
            break

primes = list(range(2,50100))
arr = []
while not arr or arr[-1] ** 2 < primes[-1]:
    f(primes,arr)
p = arr+primes

n = []
while True:
    try:
        n.append(int(input()))
    except EOFError:
        break

for i in range(len(n)):
    vol44(n[i])

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(prime_MAX,v)        
if __name__ == '__main__':
    main()

Python: import math
p = [2]
s = 3
max = 50000
last = 0

while p[last] <= max:
    m = int(math.sqrt(s))
    r = True
    for i in p:
        if i > m:
            break
        if s % i == 0:
            r = False
            break
    if r:
        p.append(s)
        last += 1
    s += 2

while True:
    try:
        n = int(raw_input())
    except EOFError as e:
        break
    i = 0
    while p[i] < n:
        i += 1
    print("%d %d" % (p[i-1], p[i+1] if p[i] == n else p[i]))