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: def create_prime(n):
    prime = [1] * (n + 1)
    prime[:2] = [0, 0]
    for i in range(len(prime)):
        if prime[i]:
            for j in range(2 * i, len(prime), i):
                prime[j] = 0
    return prime

def under(prime, n):
    for i in range(n - 1, -1, -1):
        if prime[i]:
            return i
def over(prime, n):
    for i in range(n + 1, len(prime)):
        if prime[i]:
            return i
import sys
n = [int(line) for line in sys.stdin]

prime = create_prime(max(n) + 100)

for ni in n:
    print(under(prime, ni), over(prime, ni))

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 1000000;

#define rep(i, n) for(int i=0; i<n; i++)
#define REP(n) rep(i, n)

typedef long long ll;

using namespace std;


/*
class ElectronicPetEasy
{
public:
	string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
	{
		
	}
};
*/


int prime[50000];
bool is_prime[60000];


void sieve(void)
{
	int p = 0;
	
	REP(60000) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i=2; i<60000; i++)
	{
		if (is_prime[i])
		{
			prime[p++] = i;
			for (int j=2*i; j<60000; j+=i) is_prime[j] = false;
		}
	}
}


int main()
{
	int n, less, more;
	
	sieve();
	
	while (cin >> n)
	{
		for (int i=0; i<50000; i++)
		{
			if (prime[i] > n)
			{
				more = prime[i];
				break;
			}
		}
		
		for (int i=0; i<50000; i++)
		{
			if (prime[i] >= n)
			{
				less = prime[i - 1];
				break;
			}
		}
		
		cout << less << " " << more << endl;
	}
	
	return 0;
}

C++: #include<iostream>
using namespace std;

int main(){
  int table[55000]={};
  for(int i=2; i*i<55000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=55000; j+=i){
        table[j]=1;
      }
    }
  }
  for(int i=0; i<100; ++i){
    if(table[i]==0){
      cout << i << " ";
    }
  }
  int n;
  while(cin >> n,n){
    int i;
    for(i=n-1; table[i]; --i);
    cout << i << " ";
    for(i=n+1; table[i]; ++i);
    cout << i << endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
set<int> primes={2,3,5,7,11,13,17,19,23,29,31,37,
                 41,43,47,53,59,61,67,71,73,79,
                 83,89,97,101,103,107,109,113,127,131,
                 137,139,149,151,157,163,167,173,179,181,
                 191,193,197,199,211,223,227};
bool isPrime(int n){
  for(int p:primes){
    if(p*p>n)return true;
    if(n%p==0)return false;
  }
  return true;
}
int main(){
  for(int i=229;i<50040;i+=2)
    if(isPrime(i))
      primes.insert(i);
  int n;
  while(cin>>n){
    auto r=primes.lower_bound(n);
    auto l=r;
    if(primes.count(n)==1){
      r++;l--;
    }
    else{
      l--;l--;
    }
    cout<<(*l)<<" "<<(*r)<<endl;
  }
}

C++: #include <cstdio>
#include <cstring>
using namespace std;

int main() {
  bool p[60001];
  int n, x;

  memset(p, 0, sizeof(bool)*60001);
  for (int i=2; i*i<=60000; i++) {
    if (!p[i]) {
      for (int j=2*i; j<=60000; j+=i) {
        p[j] = true;
      }
    }
  }
  while (scanf("%d", &n) == 1) {
    x = n-1;
    while (p[x]) --x;
    printf("%d ", x);
    x = n+1;
    while (p[x]) ++x;
    printf("%d\n", x);
  }
  return 0;
}

C++: #include<iostream>
using namespace std;

int main(){
  int n;
  while(cin >> n,n){
    int max=0;
    for(int i=1; i<n; ++i){
      if(i%2==0){break;}
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%j==0){frg=false; break;}
      }
      if(frg && max<i){max=i;}
    }
    cout << max << " ";
    for(int i=n+1; i<2*n; ++i){
      if(i%2==0){break;}
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i << endl;break;}
    }
  }
  return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int x[1000000];
int main() {
	for (int i = 2; i < 1000000; i++) {
		for (int j = 2; j <= sqrt(i); j++) {
			if (i%j == 0) {
				goto E;
			}
		}
		x[i] = 1;
	E:;
	}
	int a, b;
	while (cin >> a >> b) {
		for (int i = a; i >= 0; i--) {
			if (x[i] == 1) { cout << i << ' '; break; }
		}
		for (int i = a; i < 1000000; i++) {
			if (x[i] == 1) { cout << i << endl; break; }
		}
	}
}

C++: #include <iostream>
#include <vector>
using namespace std;

const int MAX = 100000;

int main ()
{
    vector<int> num(MAX + 1, 1);
    num[0] = num[1] = -1;
    for (int i = 2; i <= MAX / 2; i++) {
        for (int j = 2; i * j <= MAX; j++) {
            num[i*j] = -1;
        }
    }

    vector<int> prim;
    for (int i = 0; i < num.size(); i++) {
        if (num[i] == 1) {
            prim.push_back(i);
            num[i] = prim.size() - 1;
        }
    }

    int n;
    while (cin >> n) {
        cout << prim[num[n]-1] << " " << prim[num[n]+1] << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX 60000
int main( void )
{
	vector <bool> primes( MAX+1, false );
	for ( int i = 3; i <= MAX; i += 2 )
		primes[i] = true;
	primes[0] = false;
	primes[1] = false;
	primes[2] = true;

	for ( int i = 3; i <= MAX; i+=2 )
	{
		if ( primes[i] )
		{
			for ( int j = i + i; j <= MAX; j += i )
			{
				primes[j] = false;
			}
		}
	}

	int n;
	while ( cin >> n )
	{
		int max = 0, min = 0;
		int p = n + 2;
		while( !min )
		{
			if ( primes[p] )
				min = p;
			else
				p += 2;
		}
		p = n%2?n:n-1;
		p -= 2;
		while( !max )
		{
			if ( primes[p] )
				max = p;
			else
				p -= 2;
		}

		cout << max << " " << min << endl;
	}

}

C++: #include <iostream>
#include <vector>
#include <cstdlib>
using namespace std;

int main() {
	int n;
	int cnt = 0;
	while(cin >> n) {
		cnt++;
	}
	if(cnt > 1000)
		abort();
}

C++: #include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;
bool isPrime(int num);

int main(){
	int n;
	while(cin >> n, n){
		int prev = 0, next = 0;
		
		for(int i = num-2; i >= 3; i -= 2){
			if(isPrime(i))(
				prev = i;
				break;
			}
		}
		
		for(int i = num+2; i <= 50000; i += 2){
			if(isPrime(i){
				next = i;
				break;
			}
		}
		
		cout << prev << " " << next << endl;
	}
	return 0;
}

bool isPrime(int num){
	if(num < 2)
		return false;
	
	for(int i = 2; i*i <= num; i++){
		if(num % i == 0)
			return false;
	}
	return true;
}

C++: #include<stdio.h>
int table[55000];

int main(){
	for(int i=2;i<1000;i++){
		if(table[i]==0){
			for(int j=i*2;j<=55000;j+=i){
				table[j]=1;
			}
		}
	}
	int a;
	while(~scanf("%d",&a)){
		int i;
		for(i=a-1;table[i]==1;i--);
		printf("%d ",i);
		for(i=a+1;table[i]==1;i++);
		printf("%d\n",i);
	}
}