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: MAX = 60000
lst = [i for i in range(MAX)]
lst[0] = lst[1] = 0
for i in range(MAX):
  if lst[i] != 0:
    for j in range(i * 2, MAX, i):
      lst[j] = 0
while 0 == 0:
  try:
    n = int(input())
    i = n - 1
    j = n + 1
    while lst[i] == 0:
      i -= 1
    while lst[j] == 0:
      j += 1
    print(str(lst[i]) + " " + str(lst[j]))
  except EOFError:
    break

Python: def sieve(n):
    res = []
    nums = [1] * n
    nums[0] = 0
    for i in range(int(n ** 0.5) + 1):
        if nums[i] == 0: continue
        j = 2
        while (i + 1) * j <= n:
            nums[(i+1) * j - 1] = 0
            j += 1
    for i in range(len(nums)):
        if nums[i] == 1:
            res.append(i+1)
    return res

primes = sieve(50000)

while True:
    try:
        n = int(input())
        minn, maxn = 0, 0
        for i in range(len(primes)):
            if primes[i] > n:
                maxn = primes[i]
                minn = primes[i-1]
                if minn == n: minn = primes[i-2]
                break
        print('%d %d' % (minn, maxn))
    except:
        break

Python: from math import sqrt, ceil

N = 53000
temp = [True]*(N+1)
temp[0] = temp[1] = False
for i in range(2, ceil(sqrt(N+1))):
    if temp[i]:
        temp[i+i::i] = [False]*(len(temp[i+i::i]))

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

Python: MAX = 60000
lst = [i for i in range(MAX)]
lst[0] = lst[1] = 0
for i in range(MAX):
  if lst[i] != 0:
    for j in range(i * 2, MAX, i):
      lst[j] = 0
while 0 == 0:
  try:
    n = int(input())
    i = n - 1
    j = n + 1
    while lst[i] == 0:
      i -= 1
    while lst[j] == 0:
      j += 1
    print(lst[i],lst[j])
  except EOFError:
    break

Python: def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]


if __name__ == "__main__":
    all_primes = primes(60000)
    while True:
        try:
            n = int(input())
            ps = primes(n)
            x = ps[-1] if ps[-1] != n else ps[-2]
            y = all_primes[len(ps)]
            print("{} {}".format(x, y))
        except:
            break

Python: def sieve(n):
    res = []
    nums = [1] * n
    nums[0] = 0
    for i in range(int(n ** 0.5) + 1):
        if nums[i] == 0: continue
        j = 2
        while (i + 1) * j <= n:
            nums[(i+1) * j - 1] = 0
            j += 1
    for i in range(len(nums)):
        if nums[i] == 1:
            res.append(i+1)
    return res

primes = sieve(50021)

while True:
    try:
        n = int(input())
        minn, maxn = 0, 0
        for i in range(len(primes)):
            if primes[i] > n:
                maxn = primes[i]
                minn = primes[i-1]
                if minn == n: minn = primes[i-2]
                break
        print('%d %d' % (minn, maxn))
    except:
        break

Python: 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: 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,50000))
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 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]) > 0:
      continue
    print(i)
    break

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0044
?´???°II
"""
import sys


def create_prime_list(limit):
    """ ??¨??????????????????????????§limit?????§????´???°?????????????±???????
    https://ja.wikipedia.org/wiki/%E3%82%A8%E3%83%A9%E3%83%88%E3%82%B9%E3%83%86%E3%83%8D%E3%82%B9%E3%81%AE%E7%AF%A9
    """
    x = limit**0.5
    primes = []
    # print('x={0}'.format(x))
    nums = [x for x in range(2, limit+1)]
    while nums[0] <= x:
        primes.append(nums[0])
        current_prime = nums[0]
        nums = [x for x in nums if x % current_prime != 0]
    primes.extend(nums)
    # print(primes)
    return primes


def main(args):
    primes = create_prime_list(50000)  # ?´???°????????????????????¨???
    
    for line in sys.stdin:  # ??????????????\???
        limit = int(line.strip())
        unders = [x for x in primes if x < limit]
        largest_prime = unders[-1]
        overs = [x for x in primes if x > limit]
        smallest_prime = overs[0]
        
        # ???????????????
        print('{0} {1}'.format(largest_prime, smallest_prime))


if __name__ == '__main__':
    main(sys.argv[1:])

Python: import math
def p_l(n):
    for i in range(n-1, 1, -1):
        flag=0
        for j in range(2, int(math.sqrt(i)) + 1):
            if i % j == 0:
                flag=1
        if flag==1:continue
        return i
def p_h(n):
    for i in range(n+1,50022):
        flag=0
        for j in range(2, int(math.sqrt(i)) + 1):
            if i % j == 0:
                flag=1
        if flag==1:continue
        return i   
while 1:
    try:
        n=int(input())
        print(p_l(n),p_h(n))
    except:break

Python: pr=[True]*50001
for i in range(2,224):
    if pr[i]:
        for j in range(i*2,50001,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,50001):
        if pr[i]:
            print(i)
            break