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
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool p[50001];

void prime() {
  fill(p, p+50001, true);
  p[0] = false;
  p[1] = false;

  for(int i = 2; i < 50001; i++) {
    if(p[i]) {
      for(int j = 2; i*j < 50001; j++) {
	p[i*j] = false;
      }
    }
  }
}

int main() {
  int n, min, max;
  prime();
  
  while(cin >> n) {
    max = 2;
    for(int i = 3; i < n; i++) {
      if(p[i] && max < i) max = i;
    }
    for(int i = n+1; i < 50001; i++) {
      if(p[i]) {
	min = i;
	break;
      }
    }
    cout << max << ' ' << min << endl;
  }
}

C++: const int MAX_NUM = 100000000;
bool prime_number[MAX_NUM];
 
void prime_create() {
    fill(prime_number, prime_number + MAX_NUM, true);
    prime_number[0] = prime_number[1] = false;
 
    for(int i = 2; i < MAX_NUM; i++) {
        if(prime_number[i])
        for(int j = 2; i*j < MAX_NUM; j++) {
            prime_number[i*j] = false;
        }
    }
}

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

int main(void){
    int n,flag=0;
    while (cin>>n) {
        if (n==3) {
            cout<<2<<" "<<5<<endl;
        } else if (n%2==0) {
            for (int i=n-1;i>0;i-=2) {
                double sqrtNum=sqrt(i);
                for (int j=3;j<sqrtNum;j+=2) {
                    if (i%j==0) {
                        flag=1;
                        break;
                    }
                }
                if (flag==0) {
                    cout<<i<<" ";
                    break;
                } else {
                    flag=0;
                }
            }
            for (int k=n+1;k>0;k+=2) {
                double sqrtNum=sqrt(k);
                for (int l=3;l<sqrtNum;l+=2) {
                    if (k%l==0) {
                        flag=1;
                        break;
                    }
                }
                if (flag==0) {
                    cout<<k<<endl;
                    break;
                } else {
                    flag=0;
                }
            }
        } else {
            for (int m=n-2;m>0;m-=2) {
                double sqrtNum=sqrt(m);
                for (int o=3;o<sqrtNum;o+=2) {
                    if (m%o==0) {
                        flag=1;
                        break;
                    }
                }
                if (flag==0) {
                    cout<<m<<" ";
                    break;
                } else {
                    flag=0;
                }
            }
            for (int p=n+2;p>0;p+=2) {
                double sqrtNum=sqrt(p);
                for (int q=3;q<sqrtNum;q+=2) {
                    if (p%q==0) {
                        flag=1;
                        break;
                    }
                }
                if (flag==0) {
                    cout<<p<<endl;
                    break;
                } else {
                    flag=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;
      }
    }
  }

  int n;
  while(cin >> n,n){
    int i;
    for(i=n-1; table[i]==1; --i);
    cout << i << " ";
    for(i=n+1; table[i]==1; ++i);
    cout << i << endl;
  }
  return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

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





int main() {
    vector<bool> is_sosu(60000, true);
    is_sosu[0] = false;
    is_sosu[1] = false;
    for(ll i = 2; i <= 55000; i++){
        if(!is_sosu[i]) continue;
        for(ll j = i * 2; j <= 55000; j += i){
            is_sosu[j] = false;
        }
    }
    
    ll n;
    while(scanf("%lld", &n) != EOF){
        for(ll i = n - 1; i >= 0; i--){
            if(is_sosu[i]){
                cout << i << " ";
                break;
            }
        }
        for(ll i = n + 1; i <= 55000; i++){
            if(is_sosu[i]){
                cout << i << endl;
                break;
            }
        }
    }
}

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

using namespace std;



int main(){
	int in;
	int prime[50001] = {};

	vector<int> p;
	int i, j;
	for (i = 2; i*i < 50000; i++){
		if (prime[i] == 0){
			for (j = 2; i*j <= 50000; j++){
				prime[i*j] = 1;
			}
		}
	}
	for (i = 1; i < 50001; i++){
		if (prime[i] == 0){
			p.push_back(i);
		}
	}

	

	while (cin >> in){
		for (i = 1; i < (int)p.size(); i++){
			if (in == p[i]){
				cout << p[i - 1] << " " << p[i+1] << endl;
				break;
			}else if (in < p[i]){
				cout << p[i - 1] << " " << p[i] << endl;
			}
		}
	}


}