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 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)
    if n == 3:
      print(2, end=" ")
    else:
      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 + 1000):
      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

Python: N = 50001
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

    print(minv, maxv)

Python: import math

def prime(x):
    for i in range(2, int(math.sqrt(x))+1):
        if x%i==0:
            return 0
    return 1

prime_list = []
for i in range(2,50022):
    if prime(i)==1:
        prime_list.append(i)
while True:
    try:
        n = int(input())
    except:
        break
    print(max([x for x in prime_list if x < n]), end=' ')
    print(min([x for x in prime_list if x > n]))

Python: from math import sqrt

n = 50022
p = [1 for i in range(n)]
p[0] = 0
for i in range(1,int(sqrt(n))):
    if p[i]:
        for j in range(2*(i+1)-1,n,i+1):
            p[j] = 0

pmax = [0 for i in range(50022)]
pmin = [0 for i in range(50022)]
prev = 2

for i in range(50022):
    if p[i]:
        pmax[i] = i+1
        prev = i+1
    else:
        pmax[i] = prev
prev = 50021
for i in range(50001)[::-1]:
    if p[i]:
        pmin[i] = i+1
        prev = i+1
    else:
        pmin[i] = prev

while(1):
    try:
        n = int(input())
        print(pmax[n-2],pmin[n])
    except EOFError:
        break

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 + 1000):
      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

Python: import sys
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
for e in sys.stdin:
 N=int(e)
 mx=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: def main():
    while True:
        try:
            value = int(input())
            prime_MAX = 0
            for v in range(2,value-1):
                flag = 0
                for _v in range(2,v):
                    if v%_v == 0:
                        flag = 777
                        break
                if flag == 0:
                    prime_MAX = v 

            for v in range(value+1,50000):
                flag = 0
                for _v in range(2,v):
                    if v%_v == 0:
                        flag = 777
                        break
                if flag == 0:
                    print(str(prime_MAX)+" "+str(v))
                    break
                
        except EOFError:
            break

if __name__ == '__main__':
    main()

Python: def main():
    while True:
        try:
            value = int(input())
            prime_MAX = 0
            for v in range(2,value-1):
                flag = 0
                for _v in range(2,int(v**0.5)):
                    if v%_v == 0:
                        flag = 777
                        break
                if flag == 0:
                    prime_MAX = v 

            for v in range(value+1,50000):
                flag = 0
                for _v in range(2,int(v**0.5)):
                    if v%_v == 0:
                        flag = 777
                        break
                if flag == 0:
                    print(str(prime_MAX)+" "+str(v))
                    break
                
        except EOFError:
            break

if __name__ == '__main__':
    main()

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

Python: a = [0, 0, 1, 1] + [0, 1] * 25009
for i in range(3, 50022, 2):
    if a[i]:
        for j in range(2, 50021 // i + 1):a[i * j] = 0
while 1:
    try:
        n = int(input())
        print("{} {}".format(n - 1 - a[:n][::-1].index(1), n + 1 + a[n + 1:].index(1)))
    except:break