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 math
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())
            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(str(prime_MAX)+" "+str(v))        
        except EOFError:
            break

if __name__ == '__main__':
    main()

Python: primes = [0, 0] + [1]*50020
for i in range(2, 225):
    if primes[i]:
        for j in range(i*i, 50022, i):
            primes[j] = 0
while True:
    try:
        n = int(input())
    except:
        break
    m, o = n-1, n+1
    while not primes[m]:
        m -= 1
    while not primes[o]:
        o += 1
    print(m, o)

Python: primes = [0, 0] + [1]*49999
for i in range(2, 224):
    if primes[i]:
        for j in range(i*i, 50001, i):
            primes[j] = 0
while True:
    try:
        n = int(input())
    except:
        break
    m, o = n-1, n+1
    while not primes[m]:
        m -= 1
    while not primes[o]:
        o += 1
    print(m, o)

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
        under = p
    print(under, upper)

Python: # Aizu Problem 0009: Prime Number
#
import sys, math, os, bisect

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


def primes2(n):
    """ Input n>=6, Returns a list of primes, 2 <= p < n """
    n, correction = n-n%6+6, 2-(n%6>1)
    sieve = [True] * (n//3)
    for i in range(1,int(n**0.5)//3+1):
      if sieve[i]:
        k=3*i+1|1
        sieve[      k*k//3      ::2*k] = [False] * ((n//6-k*k//6-1)//k+1)
        sieve[k*(k-2*(i&1)+4)//3::2*k] = [False] * ((n//6-k*(k-2*(i&1)+4)//6-1)//k+1)
    return [2,3] + [3*i+1|1 for i in range(1,n//3-correction) if sieve[i]]

primes = primes2(50000)

for line in sys.stdin:
    n = int(line)
    if n in primes:
        idx = primes.index(n)
        print(primes[idx-1], primes[idx+1])
    #idx = bisect.bisect_right(primes, n)
    #print(idx)

Python: # 04.77 sec -> Time Limit Exceeded?
import sys
import math

# Sieve of Eratosthenes
N = 50000
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)


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: # -*- 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, 3, -1):
        if is_prime(i):
            answer0 = i
            break

    for i in range(n+1, 50000):
        if is_prime(i):
            answer1 = i
            break

    print(answer0, answer1)

Python: def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

MAX = 60000
primes = list()
for i in range(MAX):
    primes.append(True)
primes[0] = False
primes[1] = False

for i in range(2, MAX):
    j = i + i
    while j < MAX:
        primes[j] = False
        j = j + i

N = list(get_input())
for l in range(len(N)):
    n = int(N[l])
    d = 1
    while True:
        if primes[n-d]:
            print(n-d, end=" ")
            break
        d += 1

    d = 1
    while True:
        if primes[n+d]:
            print(n+d)
            break
        d += 1

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_left(primes, num+1)
    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: import math

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

while True:
    try: n = int(input())
    except: break
    
    low_prime = 0
    for i in range(n-1, 0, -1):
        if is_prime(i):
            low_prime = i
            break
    
    high_prime = n + 1
    while True:
        if is_prime(high_prime):
            break
        else:
            high_prime += 1

    print('{} {}'.format(low_prime, high_prime))