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;
 
bool is_prime(int n){
  if(n <= 1)
    return false;
 
  for(int i=2;i*i<=n;i++){
    if(n%i == 0)
      return false;
  }
  return true;
}
 
int main(){
    int n;
 
    bool is_prime[1000000];
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<1000000;i++){
      is_prime[i] = true;
    }
    for(int i=2; i*i<1000000; i++){
      if(is_prime[i]){
        for(int j=i*i;j<1000000; j+=i){
          is_prime[j] = false;
        }
      }
    }
 
    int n_prime[1000000];
 
    int cnt = 0;
    for(int i=0;i<1000000;i++){
      if(is_prime[i]){
        cnt++;
      }
      n_prime[i] = cnt;
    }
 
    while(1){
      int primen;
      cin >> n;
      if(cin.eof())
        break;
 
      for(int i=n-1;;i--){
        if(is_prime[i]){
          cout << i << " ";
          break;
        }
      }
 
      for(int i=n+1;;i++){
        if(is_prime[i]){
          cout << i << endl;
          break;
        }
      }
    }
 
}

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



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




int main(){
	int n, min=0, max=0, i=1;
	while(cin >> n){
		min=0;max=0;i=1;

		while(min==0 || max==0){
			if( max==0 && judgePrimenum(n+i) )max=n+i;
			if( min==0 && judgePrimenum(n-i) )min=n-i;
			++i;
		}

		cout << min << " " << max << endl;
	}
	return 0;
}

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

int main(int argc, char** argv) {
	int n;
	while (cin >> n) {
		bool data[200050] = { 0 };
		for (int j = 4; j < 50200; j = j + 2) {
			data[j] = 1;
		}
		for (int i = 3; i < 50200; i = i + 2) {
			for (int j = 2 * i; j < 50200; j = j + i) {
				data[j] = 1;
			}
		}

		for (int i = n - 1; i >= 2; --i) {
			if (!data[i]) {
				cout << i;
				break;
			}
		}
		for (int i = n + 1; i < 50200; ++i) {
			if (!data[i]) {
				cout << " " << i << endl;
				break;
			}
		}
	}
}

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

int P[50010];
map<int,int> idx;

int prime() {
  int i=3,j,k,cnt=1;
  P[0] = 2;
  for(i=3;i<=60000;i+=2){
    k=0;
    for(j=3;j<=sqrt(i);j+=2){
      if(i%j==0){
	k=1;
	break;
      }
    }
    if(k==0) {
      P[cnt] = i;
      cnt++;
    }
  }
  return cnt;
}

int main(){
  int n,cnt;
  cnt = prime();
  while(cin >> n){
    for(int i=0;i<cnt;i++){
      if(n == P[i]){
	cout << P[i-1] << " " << P[i+1] << endl;
	break;
      }
      else if(n < P[i]){
	cout << P[i-1] << " " << P[i] << endl;
	break;
      }
    }
  }
}

C++: MAX = 60000
lst = [i for i in range(MAX)]
lst[0] = lst[1] = 0
for i in range(MAX):
  if lst[i] != 0:
    for j in range(i * 2, MAX, i):
      lst[j] = 0
while 0 == 0:
  try:
    n = int(input())
    i = n - 1
    j = n + 1
    while lst[i] == 0:
      i -= 1
    while lst[j] == 0:
      j += 1
    print(lst[i],lst[j])
  except EOFError:
    break

C++: /////////////////////////////////////////////////////////
//
//  c/temp.cpp file
//  Last Updated: 2018-10-23 ...Maybe
//
//    I hope you adding this code to the setting file
//    alias g++='g++ -std=c++1y -DDEBUG_LOCAL'
//
/////////////////////////////////////////////////////////

#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back

//#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _REP(i,n) REAP(i,0,n)
#define REAP(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(...) _overload3(__VA_ARGS__,REAP,_REP,)(__VA_ARGS__)

#define _REPR(i,n) REAPR(i,n,0)
#define REAPR(i,a,b) for(int i=int(a-1);i>=int(b);--i)
#define REPR(...) _overload3(__VA_ARGS__,REAPR,_REPR,)(__VA_ARGS__)

#define ALL(a) a.begin(),a.end()
#define rALL(a) a.rbegin(),a.rend()

#define coutALL(a) {int loop_coutALL=0;for(auto e:a) cout<<(loop_coutALL++?" ":"")<<e; cout<<endl;}

#define coutYN(a) cout<<((a)?"YES":"NO")<<endl;
#define coutYn(a) cout<<((a)?"Yes":"No")<<endl;
#define coutyn(a) cout<<((a)?"yes":"no")<<endl;

#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)

const int INF=1145141919;
//const long long INF=114514191911451419;
const int MOD=(int)1e9+7;
const double EPS=1e-12;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;

typedef pair<int,int> pii;
typedef pair<int,string> pis;
typedef pair<string,int> psi;
typedef pair<string,string> pss;

typedef long long ll;

template<typename T> istream &operator >> (istream &is, vector<T> &v){for(T &x:v) is>>x;return is;}
template<typename T> ostream &operator << (ostream &os, vector<T> &v){int i=0;for(T &x:v) os<<(i++?" ":"")<<x;return os;}

ll rev(ll n){ll x=0;for(;n>0;){x=x*10+n%10;n/=10;}return x;}

ll upper(ll n,ll m){return (n+m-1)/m;};
ll rounding(ll n){return (long double)n+0.5;};

bool inG(ll x,ll n){return 0<=x && 0<n;}
bool outG(ll x,ll n){return x<0 || n<=x;}

inline int qp(int a,ll b){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
inline int qp(int a,ll b,int mo){if(!b)return 1;int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

inline ll fac(ll k,ll n){ll a=1;for(int i=0;i<n;i++)a*=k--;return a;}
inline ll fac(ll k,ll n,int mo){ll a=1;for(int i=0;i<n;i++)a*=k--,a%=mo;return a;}

inline int dsum(ll n){int a=0;for(;n;n/=10)a+=n%10;return a;}

struct Arithmetic{Arithmetic(){cin.tie(0);ios::sync_with_stdio(0);cout<<fixed<<setprecision(20);}};

//#define DEBUG_LOCAL

#ifdef DEBUG_LOCAL
template<typename T> void deb(T a){cerr<<"deb: "<<a<<"です"<<endl;}
#define debl {cerr<<"debug: "<<__LINE__<<"行目だ"<<endl;}
void what_cr(){cout<<__GCC_ATOMIC_CHAR16_T_LOCK_FREE<<" ←？"<<endl;}
//ori_func S

//ori_func E
#else
template<typename T>void deb(T a){}
#define debl
void what_cr(){}void t_t(){}
#endif

const int MAX_primear=1e6; // 1e8=x, 1e7=? 1e6=o
int primear[MAX_primear+1]={};
vector <int> prime;
void eratos_sieve(){
  for(int i=2;i<=MAX_primear;i++){
    if(!primear[i]){
      prime.push_back(i);
      primear[i]=2;
      for(int j=i*2;j<=MAX_primear;j+=i) primear[j]=1;
    }
  }
}

signed main(){

  Arithmetic Exception;

  eratos_sieve();

  for(int n;cin>>n;){

    cout<<*(lower_bound(ALL(prime),n)-1)<<" "<<*upper_bound(ALL(prime),n)<<endl;

  }

  return 0;

}

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