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>
#include <vector>
using namespace std;
typedef vector <int> vi;
#define REP1(i,n1,n2) for (int i=n1; i<n2; i++)
vi primes;

int get_primes(int m){
    int n = (m+1)/2, root = (int)(pow(n, 0.5));
    vector <bool> N(n, true);
    N[0]=false;

    if (m>1) primes.push_back(2);
    REP1(i,1,root){
        int tmp = i*2+1;
        if (N[i]){
            primes.push_back(tmp);
            for (int j=i+tmp; j<n+1; j+=tmp)
				N[j]=false;
        }
    }
    REP1(i,root,n+1)
        if(N[i]) primes.push_back(2*i+1);
    return 0;
}

int main(){
	get_primes(50100);
	while (true){
		int n,a,b;
		cin>>n;
		if (cin.eof()) break;
		REP1(i,0,(int)primes.size()){
			a=primes[i];
			if (a<n) b=a;
			else if (a>n) break;
		}
		cout<<b<<" "<<a<<endl;
	}
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> sosu(60000, 1);

void eratos() {
  for(int i = 2; i < 30000; i++) {
    sosu[2*i] = 0;
  }
  for(int i = 3; i < sqrt(60000); i+=2) {
    if(sosu[i] == 1) {
      for(int j = 1; i*(j+2) < 60000; j++) {
	sosu[i*(j+2)] = 0;
      }
    }
  }
}

int main() {
  eratos();

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

C++: #include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<double,double> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
vector<bool> eratosthenes(int n){
    vector<bool> prime(n,true);
    prime[0]=false;prime[1]=false;
    for(int i=2;i<=n;i++){
        if(prime[i]){
            for(int j=i*2;j<=n;j+=i){
                prime[j]=false;
            }
        }
    }
    return prime;
}
int main(){
    vector<bool> p=eratosthenes(60000);
    int n;
    while(cin>>n){
        for(int i=n-1;i>=0;i--){
            if(p[i]){
                cout<<i<<" ";
                break;
            }
        }
        for(int i=n+1;i<=60000;i++){
            if(p[i]){
                cout<<i<<endl;
                break;
            }
        }
    }
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>

#define NUM 50020

int main(){
	int table[NUM],limit;

	for(int i=0; i < NUM;i++)table[i] = 1;
	table[0] = 0;

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	int n;

	while(scanf("%d",&n)!=EOF){
		for(int k=n-1;k>=0;k--){
			if(table[k] == 1){
				printf("%d ",k);
				break;
			}
		}
		for(int k=n+1;k<NUM;k++){
			if(table[k] == 1){
				printf("%d\n",k);
				break;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void) {
  bool prime[60000];
  memset(prime, true, sizeof(prime));
  prime[0] = prime[1] = false;
  for (int i = 2; i * i <= 50100; i++) {
    if (prime[i]) {
      for (int j = 2 * i; j <= 50100; j += i) {
        prime[j] = false;
      }
    }
  }

  int n;
  while (cin >> n) {
    for (int i = n - 1; i >= 2; --i)
      if (prime[i]) {
        cout << i << " ";
        break;
      }
    FOR(i, n + 1, 51000) if (prime[i]) {
      cout << i << 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<bits/stdc++.h>
using namespace std;

#define MAX_N 50010

int prime[MAX_N];
bool is_prime[MAX_N + 1];

void sieve(int n){
	int p = 0;
	for(int i = 0; i <= MAX_N; i++) is_prime[i] = true;

	is_prime[0] = is_prime[1] = false;

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


	for(int i = 0; i < MAX_N; i++){

		if(prime[i] == n){
			cout << prime[i-1] << " " << prime[i+1] << endl;;
			break;
		}
		else if(prime[i] > n){
			cout << prime[i-1] << " " << prime[i] << endl;
			break;
		}
		else continue;
	}
}

int main(){
	int n;
	while(cin >> n){
		sieve(n);
	}
}

C++: // 素数を和を求めるプログラム
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

int main(void)
{
    bool flag = true;
    int n, num, last_num, loop_count = 0;
    vector<int> prime;

    // 初期値の設定
    num = last_num = 2;
    prime.push_back(num);

    while( loop_count < 50)
    {
        cin >> n;
        // 前回見つかった最後の素数値を代入
        num = last_num;

        // 素数を探索する処理
        while( last_num <= n )
        {
            num++;
            flag = true;

            for(unsigned int i = 0; i < prime.size(); i++)
            {
                if( num % prime[i] == 0 )
                {
                    // 素数で割り切れる数は, 素数ではない
                    flag = false;
                    break;
                }
            }

            if( flag == true )
            {
                // 素数が見つかった
                prime.push_back(num);
                // 見つかった最後の素数を記憶する
                last_num = num;
            }
        }

        for(unsigned int i = 0; i < prime.size(); i++)
        {
            // 目的の素数値の前後の値を表示する
            if( prime[i] == n )
            {
                printf("%d %d\n", prime[i - 1], prime[i + 1]);
            }
        }

        loop_count++;

    }

    return 0;
}

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

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int const N = 51000;
  vector<int> prime(N,1);
  prime[0] = prime[1] = 0;
  for(int i=0; i*i<N; i++)
    if (prime[i])
      for(int j=i*2; j<N; j+=i)
        prime[j] = 0;
  vector<int> p;
  for (int i=0; i<N; i++)
    if (prime[i])
      p.push_back(i);
  int n;
  while(cin>>n) {
    vector<int>::iterator it = upper_bound(ALL(p),n);
    int f = 1;
    if (*(it-1) == n) f++;
    printf("%d %d\n",*(it-f), *it);
  }
}