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<iostream>
using namespace std;

int main(){
  int table[80000]={};
  for(int i=2; i*i<80000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=80000; j+=i){
        table[j]=1;
      }
    }
  }
  
  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"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.answer"

bool isso(long long int a) {
	if (a == 1 || a == 0)return false;
	for (long long int i = 2; i*i <= a; ++i) {
		if ((a%i)) {
		}
		else {
			return false;
		}
	}
	return true;
}
int main() {
	
	int N;
	while (cin>>N) {
		for (int i = N - 1;; --i) {
			if (isso(i)) {
				cout << i << " ";
				break;
			}
		}
		for (int i = N + 1;; ++i) {
			if (isso(i)) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

vector<int> primes;
bool isPrime[60000];

void erats(){
	fill(isPrime,isPrime+60000,true);
	isPrime[0]=false;
	isPrime[1]=false;
	for(int i = 2; i < 60000; i++){
		if(isPrime[i]){
			primes.push_back(i);
			for(int j = 2*i; j < 60000; j+=i){
				isPrime[j]=false;
			}
		}
	}
}


int main(){

	int n;
	erats();
	while(cin>>n&&n!=0){
		for(int j = n-1; ; j--){
			if(isPrime[j]){
				cout<<j<<" "<<flush;
				break;
			}
		}
		for(int j = n+1; ;j++){
			if(isPrime[j]){
				cout<<j<<endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
int p[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  loop(i,2,M){
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n){
    int i = n - 1;
    while(!prime[i]);cout<<i<<" ";
    i = n + 1;
    while(!prime[i]);cout<<i<<endl;
  }
}

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[55000];

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

  for(int i = 2; i < 55000; i++) {
    if(p[i]) {
      for(int j = 2; i*j < 55000; 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 < 55000; i++) {
      if(p[i]) {
	min = i;
	break;
      }
    }
    cout << max << ' ' << min << endl;
  }
}

C++: #define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <climits>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef pair<int, int> pii;

int memo[60000] = {};
vector<int> pri;
void calc()
{
	for (int i = 2; i < 60000; i++)
	{
		if (memo[i] == 0)
		{
			pri.push_back(i);
			for (int l = i; l < 60000; l += i)
			{
				memo[l] = 1;
			}
		}
	}
}

int main()
{
	calc();
	int n;
	while (cin >> n)
	{
		cout << *(lower_bound(all(pri), n)-(int)binary_search(all(pri),n)) << " " << *(lower_bound(all(pri), n) + 1) << endl;
	}
}

C++: #include <iostream>

using namespace std;

bool prime_table[100000];
int n;

void make_table() {
    for (int i = 0; i < 100000; i++) 
        prime_table[i] = true;

    prime_table[0] = false;
    prime_table[1] = false;

    for (int i = 2; i + i < 100000; i++) {
        if (prime_table[i]) {
            for (int j = i + i; j < 100000; j += i) {
                prime_table[j] = false;
            }
        }
    }
}

void solve() {
    int i;
    for (i = n-1; !prime_table[i]; i--);

    int j;
    for (j = n+1; !prime_table[j]; j++);
    cout << i << ' ' << j << endl;
}

int main() {
    make_table();
    while (cin >> n) {
        solve();
    }
    return 0;
}

C++: #include<iostream>
using namespace std;
bool prime(int n){
	for(int i=2;i<n;i++){
		if(n%i==0)return false;
	}
	return true;
}

int main(){
	int x,xx;
	while(cin>>x){
		xx=x-1;
		while(prime(xx)==false)xx--;
		cout<<xx<<" ";
		xx=x+1;
		while(prime(xx)==false)xx++;
		cout<<xx<<endl;
	}
}