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])
    }
}

C++: #include <cstdio>
#include <utility>
#include <cstdlib>
#include <cmath>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s){int c;
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

unsigned long powm(int b, int n, int m) {
	if (n == 0)
		return 1;
	else if (n == 1)
		return b % m;
	unsigned long t = powm(b, n / 2, m);
	return t * t % m * (n % 2 ? b : 1) % m;
}


bool fermat(int n) {
	for (int i = 0; i < log(n) * 3; i++) {
		int r = rand();
		if (r % n && powm(r, n - 1, n) != 1)
			return false;
	}
	return true;
}

bool is_prime(int n) {
	return fermat(n);
}

int main() {
	for (int n; scan(n);) {
		for (int i = n - 1;; i--)
			if(is_prime(i)) {
				out(i, ' ');
				break;
			}
		for (int i = n + 1;; i++)
			if(is_prime(i)) {
				out(i, '\n');
				break;
			}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool* PrimeSieve(int n) {
  bool*s = new bool[n];
  for (int i = 0; i < n; ++i) s[i] = true;
  s[0] = s[1] = false;
  for (int i = 2; i < n; ++i)
    if (s[i]) for (int j = i << 1; j < n; j += i) s[j] = false;
  return s;
}

int main() {

  const int N = 50022;
  auto isprime = PrimeSieve(N);

  loop {
    int n; cin >> n;
    if (!cin) break;
    int a,b;
    for (int m = n-1; m > 0; --m) {
      if (isprime[m]) {
        a = m;
        break;
      }
    }
    for (int m = n+1; m < N; ++m) {
      if (isprime[m]) {
        b = m;
        break;
      }
    }
    cout << a << ' ' << b << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cmath>

#define NUM 100000
using namespace std;
int p[NUM];

int main(){
	int i,j;
	p[0]=0;//ツ素ツ青板テツーツブツδ仰づーツ催ャツづゥ
	p[1]=0;
	for(i=2;i<NUM;i++)p[i]=1;
	for(i=2;i<sqrt(NUM);i++){
		if(p[i]){
			for(j=i*2;j<NUM;j+=i){
				p[j]=0;//ツ倍ツ青板づーツ渉慊つュ
			}
		}
	}
	int a;
	int min,max;
	while(cin>>a){
		for(i=a-1;i>=0;i--){
			if(p[i]){
				min=i;
				break;
			}
		}
		for(i=a+1;i<=50000;i++){
			if(p[i]){
				max=i;
				break;
			}
		}
		cout<<min<<" "<<max<<endl;		
	}
	return 0;
}

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


int prime[60000];


void sieve(){
	memset(prime, 1, sizeof prime);
	int i;
	for(i = 2;i*i <= 60000;i++){
		if(prime[i]){
			for(int j = 2;i*j <= 60000;j++){
				prime[i*j] = 0;
			}
		}
	}
}


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

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

bool prime[MAX];
void calcPrime(){
	for(int i = 2; i < MAX; i++) prime[i] = true;
	for(int i = 2; i < MAX; i++){
		if( prime[i] ){
			for(int j = i+i; j <= MAX; j += i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	int n;
	calcPrime();
	while( cin >> n ){
		int under = -1, over = -1;
		for(int d = n-1, u = n+1; 0 < d || u < MAX; ){
			if( 0 < d ) d--;
			if( u < MAX ) u++;
			if( under != -1 && over != -1 ) break;
			if( prime[d] ) under = d;
			if( prime[u] ) over = u;
		}
		cout << under << " " << over << endl;
	}
}

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

bool Judge_Prime_Number( int x )
{
    for( int i = 2; i <= sqrt(x); i++ )
    {
        if( x % i == 0 )
            return false;
    }
    return true;
}

int main()
{
    int a;

    cin >> a;

    int min = a - 1, max = a + 1;

    while( Judge_Prime_Number(min) == false )
        min--;
    while( Judge_Prime_Number(max) == false )
        max++;
    
    cout << min << " " << max << endl;

    return 0;
}

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

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

int main() {
    int n, sp, lp;
    while (cin >> n) {
        for (int i=n-1; i>=2; --i) {
            if (isPrime(i)) {
                sp = i;
                break;
            }
        }
        for (int i=n+1; i<=50001; ++i) {
            if (isPrime(i)) {
                lp = i;
                break;
            }
        }
        cout << sp << " " << lp << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

void eratosthenes(bool p[], int n)
{
	for (int i=0; i<=2*n; i++) p[i] = true;
	p[1] = false;
	for (int i=2; i<=n; i++) {
		if (!p[i]) continue;
		for (int d=2; i*d<=2*n; d++) p[i*d] = false;
	}
}

int main()
{
	int n;
	bool p[100001];
	
	while (cin >> n) {
		eratosthenes(p, n);
		for (int i=n-1; i>0; i--) {
			if (p[i]) { cout << i << " "; break; }
		}
		for (int i=n+1; i<2*n; i++) {
			if (p[i]) { cout << i << endl; break; }
		}
	}
			
	return 0;
}