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
from itertools import takewhile, dropwhile

L, pn, tmp = 224, [], [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)

for line in sys.stdin:
    n = int(line.strip())
    print(list(takewhile(lambda x: x<n, pn))[-1], list(dropwhile(lambda x: x<n, pn))[1])

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: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0044
"""

from math import sqrt, ceil, pow
import bisect
import sys


# https://github.com/mccricardo/sieve_of_atkin/blob/master/sieve_of_atkin.py
class SieveOfAtkin:
    def __init__(self, limit):
        self.limit = limit
        self.primes = []
        self.sieve = [False] * (self.limit + 1)

    def flip(self, prime):
        try:
            self.sieve[prime] = True if self.sieve[prime] == False else False
        except KeyError:
            pass

    def invalidate(self, prime):
        try:
            if self.sieve[prime] == True: self.sieve[prime] = False
        except KeyError:
            pass

    def isPrime(self, prime):
        try:
            return self.sieve[prime]
        except KeyError:
            return False

    def getPrimes(self):
        testingLimit = int(ceil(sqrt(self.limit)))

        for i in range(testingLimit):
            for j in range(testingLimit):
                # n = 4*i^2 + j^2
                n = 4 * int(pow(i, 2)) + int(pow(j, 2))
                if n <= self.limit and (n % 12 == 1 or n % 12 == 5):
                    self.flip(n)

                # n = 3*i^2 + j^2
                n = 3 * int(pow(i, 2)) + int(pow(j, 2))
                if n <= self.limit and n % 12 == 7:
                    self.flip(n)

                # n = 3*i^2 - j^2
                n = 3 * int(pow(i, 2)) - int(pow(j, 2))
                if n <= self.limit and i > j and n % 12 == 11:
                    self.flip(n)

        for i in range(5, testingLimit):
            if self.isPrime(i):
                k = int(pow(i, 2))
                for j in range(k, self.limit, k):
                    self.invalidate(j)

        self.primes = [2, 3] + [x for x in range(len(self.sieve)) if self.isPrime(x) and x >= 5]
        return self.primes




def solve1(num, primes):
    #
    i = bisect.bisect_left(primes, num)
    lt = primes[i-1]
    i = bisect.bisect_right(primes, num)
    gt = primes[i]
    return lt, gt


if __name__ == '__main__':
    A = SieveOfAtkin(55000)
    A.getPrimes()
    # ??????????????\?????¨???????????????
    for line in sys.stdin:
        num = int(line)
        lt, gt = solve1(num, A.primes)
        print('{} {}'.format(lt, gt))

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
	a,b=0,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(5100)
while True:
	try:
		n=int(input())
		solve(n)
	except EOFError:
		break

Python: import math
def p_l(n):
    for i in range(n-1, 2, -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: #!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def prime(n):
    L = list(xrange(2, n))
    P = []
    while L[0] ** 2 < n:
        P.append(L[0])
        L = [i for i in L if i % P[-1]]
    return P + L

ps = prime(50030)
for line in stdin:
    n = int(line)
    for p in ps:
        if n < p:
            upper = p
            break
        if p < n:
            under = p
    print(under, upper)

Python: import sys

def check_prime(n):
    for i in range(2, n):
        if n%i == 0:
            return False
    return True

for line in sys.stdin:
    ans = ''
    for i in range(int(line)-1, 1, -1):
        c = check_prime(i)
        if c == True:
            ans += str(i)
            break
    for i in range(int(line)+1, int(line)*2+1):
        c = check_prime(i)
        if c == True:
            ans += ' '
            ans += str(i)
            break
    print(ans)

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
    i=p.index(n)
    print(p[i-1],p[i+1])

Python: import sys

def isPrime(n):
    for i in range(2,int(n**.5+1)):
        if n%i==0:
            return False
    return True

for n in sys.stdin:
    n=int(n)
    s=n-1
    while not isPrime(s):
        s-=1
    b=n+1
    while not isPrime(b):
        b+=1
    print(*[s,b])

Python: is_prime = [False,False]

for i in range(2,1000000):
    is_prime.append(True)

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

while 1:
    try:
        a = int(0)
        b = int(0)
        n = int(input())
        for i in range(n-1,0,-1):
            if is_prime[i]:
                a = i
                break
        
        for i in range(n+1,50022):
            if is_prime[i]:
                b = i
                break
                
        print("%s %d"%(a,b))
    except:
        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())
    except:
        break
    print(list(takewhile(lambda x: x<n, pn))[-1], list(dropwhile(lambda x: x<=n, pn))[0])