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<cstring>
#include<cmath>
using namespace std;

#define SIZE 100000
bool prime[SIZE];

int main(){
    memset( prime, 0, sizeof(prime) );
    for( int i=2; i<(int)sqrt(SIZE)+1; i++ ){
        if( !prime[i] ){
            for( int j=i+i; j<SIZE; j+=i ){
                prime[j] = true;
            }
        }
    }

    int n;
    while( cin >> n ){
        for( int i=n-1; i>=2; i-- ){
            if( !prime[i] ){
                cout << i;
                break;
            }
        }
        for( int i=n+1; i<SIZE; i++ ){
            if( !prime[i] ){
                cout << " " << i << endl;
                break;
            }
        }
    }
    return 0;
}

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

int main(){
  bool is_prime[50001];

  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<50001;i++){
    is_prime[i] = true;
  }

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

  int n_prime[50001];

  int cnt = 0;
  for(int i=0;i<50001;i++){<50001
    if(is_prime[i]){
      cnt++;
    }
    n_prime[i] = cnt;
  }

  while(true){
    int n;
    cin >> n;

    if(cin.eof())
        break;

    int high,low;
    for(int i=0;i<50001;i++){
      if((is_prime[i]) && (n_prime[i] == n_prime[n]-1)){
        low = i;
      }
      if((is_prime[i]) && (n_prime[i] == n_prime[n]+1)){
        high = i;
      }
    }

    cout << low << " " << high << endl;
  }

  return 0;
}

C++: #include <string>
#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
 
using namespace std;

bool isP[50001];
  
int main(){
	fill(isP, isP+50001, true);
	for(int i = 2; i <= 50000; i++){
		if(isP[i]){
			for(int j = i*2; j <= 50000; j += i){
				isP[j] = false;
			}
		}
	}

	int n;

	cin >> n;

	for(int i = n-1; i >= 2; i--){
		if(isP[i]){
			cout << i << endl;
			break;
		}
	}
	for(int i = n+1; i <= 50000; i++){
		if(isP[i]){
			cout << i << endl;
			break;
		}
	}


	return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define PRIM 50021

bool prim[50022];
int a_prime[50022];

int main(){
	memset(prim, true, sizeof(prim));
	int N;
	prim[0] = false;
	FOR(i, 1, sqrt(PRIM)) {
		if(prim[i]) {
			for(int j = (i + 1); (i + 1) * j <= PRIM; ++j) {
				prim[(i + 1) * j - 1] = false;
			}
		}
	}
	while(scanf("%d", &N)) {
		repr(i, N - 2) {
			if(prim[i]){
				printf("%d ", i + 1);
				break;
			}
		}
		FOR(i, N, PRIM) {
			if(prim[i]) {
				printf("%d\n", i + 1);
				break;
			}
		}
	}
	return 0;
}

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

const int MAX_S = 550000;
bool p[MAX_S];


void prime() {
  fill(p, p+MAX_S, true);
  p[0] = p[1] = false;
  for(int i = 2; i < MAX_S; i++) {
    if(p[i]) {
      for(int j = 2; i*j < MAX_S; j++) {
        p[i*j] = false;
      }
    }
  }
}

int main() {
  int x;
  prime();
  while(cin >> x) {
    int n = 2;
    bool b = false;
    for(int i = 2; i < MAX_S; i++) {
      if(b && n != x) {
        cout << n << endl;
        break;
      }
      if(x == i) {
        cout << n << ' ';
        b = true;
      }
      if(p[i]) n = i;
    }
  }
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
#define loop(i,b,a) for(int i = b ; i < a; i ++)
const int MAX = 50000;
bool p[MAX];
void isPrime(){
  fill(p,p + MAX,true);
  p[0] = p[1] = false;
  rep(i,MAX){
    if(p[i]){
      for(int j = i + i ; j < MAX ; j += i)
	p[j] = false;
    }
  }
} 

int main(void){
  isPrime();
  int n;
  while(cin>>n){

    int i;
 
    for(i = n-1 ; !p[i] ; i --);
    cout<<i<<" ";
    for(i = n+1 ; !p[i] ; i ++);
    cout<<i<<endl;
  }
  return 0;
}

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


void sieve(void)
{
	int p = 0;
	
	REP(50001) 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<=50000; 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int ,P> P3;
typedef pair<P ,P> PP;
const ll MOD = ll(1e9+7);
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
const double EPS = 1e-6;
const int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

vector<int> prime;
vector<int> ls;

void sieve(int N){
    prime.resize(N+1,1);
    prime[0] = prime[1] = 0;
    for(int i=2;i*i<=N;i++){
        for(int j=i*i;j<=N;j+=i){
            prime[j] = 0;
        }
    }
    for(int i=2;i<=N;i++){
        if(prime[i])ls.push_back(i);
    }
}

int main() {
    sieve(int(1e5));
    int n;
    while(cin >> n){
        int a, b;
        a = *--lower_bound(ALL(ls),n);
        b = *upper_bound(ALL(ls),n);
        cout << a << " " << b << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
int main(){
	int n,m;
	bool f[50001];
	memset(f,true,sizeof(f));
	for(int i=2;i<50001;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				f[i]=false;
				break;
			}
		}
	}
	while(cin>>n){
		for(int i=n-1;;i--){
			if(f[i]){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=n+1;;i++){
			if(f[i]){
				cout<<i;
				break;
			}
		}
		cout<<endl;
	}
	return 0;
}