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: N = 50010
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 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(50021)
while True:
	try:
		n=int(input())
		solve(n)
	except EOFError:
		break

Python: import sys
import math

primes = [2]
for line in sys.stdin:
  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

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):
                if is_prime(v):
                    prime_MAX = v
            for v in range(value+1,50001):
                if is_prime(v):
                    break
            print(str(prime_MAX)+" "+str(v))        
        except EOFError:
            break

if __name__ == '__main__':
    main()

Python: import bisect
prime = [2,3,5,7,11,13]

shieve1 = [1]*257
for i in prime:
    itr = i-1
    while(itr<256):
        shieve1[itr] = 0
        itr += i

for i in range(16,256):
    if shieve1[i]:
        prime.append(i+1)

shieve2 = [1]*(50101)

for i in prime:
    itr = i-1
    while(itr<50100):
        shieve2[itr] = 0
        itr += i

for i in range(257,50101):
    if shieve2[i]:
        prime.append(i+1)

while True:
    try:
        n = int(input())
        m = bisect.bisect(prime,n)
        if n==prime[m-1]:
            print(prime[m-2],prime[m])
        else:
            print(prime[m-1],prime[m])
    except EOFError:
        break

Python: import sys

def furui(n):
  l = [1 for i in range(n+1)]
  l[0] = 0
  l[1] = 0
  for i in range(2,n+1):
    if l[i] == 1:
      for j in range(2,n//i+1):
        l[i*j] = 0
  l2 = []
  for i in range (len(l)):
    if l[i] == 1:
      l2.append(i)
  return l2

for line in sys.stdin:
  n = int(line)
  l = furui(n)
  if max(l) == n:
    i1 = l[len(l)-2]
  else:
    i1 = max(l)
  i2 = n
  while True:
    i2 += 1
    flag = 1
    for i in l:
      if i2 % i == 0:
        flag = 0
        break
    if flag:
      break
  print(str(i1) + " " + str(i2))

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)
    print(primes[-1] if primes[-1] != n else primes[-2], end=" ")
    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

Python: p = [1] * (100000 + 1)
p[0], p[1] = 0, 0
for i in range(2, int(100000 ** 0.5) + 1):
    if not p[i]:
        continue
    for j in range(2 * i, 100000 + 1, i):
        p[j] = 0

while 1:
    try:
        n = int(input())
        bp, ap = 0, 0
        for i in range(n)[::-1]:
            if p[i] == 1:
                bp = i
                break
        for i in range(n+1, 2 * n + 1):
            if p[i] == 1:
                ap = i
                break
        print(bp, ap)
    except:
        break

Python: a = [0, 0, 1, 1] + [0, 1] * 24999
for i in range(3, 50001, 2):
    if a[i]:
        for j in range(2, 50001 // i):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

Python: check = [False,False]


for i in range(0,100000):
    check.append(True)

for i in range(2,100000):
    if(check[i]):
        for j in range(i*i,100000,i):
            check[j]=False


while True:
    try:
        x = int(input())
        a = b = x

        for i in reversed(range(0,x)):
            if(check[i]):
                a = i
                break

        while True:
            x += 1
            if(check[x]):
                b = x
                break
        
        print("%d %d"%(a,b))
        
    except:
        break

Python: import math

def first_try(num):
    list=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67]
    i=0
    tmp=int(math.sqrt(num))
    while True:
        if num in list:
            return True
        #その数を超えたら終了
        if list[i]>tmp or i==len(list)-1:
            return True
        
        if (num%list[i]==0):
            return False
        i+=1

while True:
    try:
        num=int(input())
    except:
        break

    #小さいの
    s=0
    while True:
        s+=1
        if first_try(num-s)==True:
            print(num-s,end=" ")
            break
    #大きいの
    l=0
    while True:
        l+=1
        if first_try(num+l)==True:
            print(num+l)
            break

Python: import bisect

MAX = 50050

#エラトステネスの篩
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