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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
bool isPrime(int x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

int main(){
    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;
            }
        }
    }

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

        if(cin.eof())   break;

        for(int i=n-1;i>0;i--){
            if(is_prime[i]){
                cout << i;
                break;
            }
        }
        for(int i=n+1;i<50022;i++){
            if(is_prime[i]){
                cout << " " << i << endl;
                break;
            }
        }
    }

    return 0;
}

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++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

int main()
{

	vector<int> prime;
	prime.push_back(2);
	prime.push_back(3);
	prime.push_back(5);

	for(int i=7;i<=60000;i+=2){
		bool ok=true;
		for(int j=0;prime[j]*prime[j]<=i && ok;j++){
			if(i%prime[j]==0) ok=false;
		}
		if(ok) prime.push_back(i);
//		if(ok) cout<<i<<endl;
	}

	int n;
	while(cin>>n){

		auto l=lower_bound(prime.begin(),prime.end(),n);
		auto u=upper_bound(prime.begin(),prime.end(),n);

		if(*l == n) l--;

		cout<<*l<<" "<<*u<<endl;

	}


	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
    constexpr auto N = 50021, PN = 5134;
    bool checked[N+1] = {};
    int primes[PN] = {};
    for( int i=2, ii=0; i<=N; ++i ) {
        if ( !checked[i] ) {
            primes[ii++] = i;
            for( int j=i; j<N; j+=i ) {
                checked[j] = true;
            }
        }
    }

    int n;
    while( cin >> n ) {
        for( int i=0; i<PN; ++i ) {
            if ( primes[i] >= n ) {
                cout << primes[i-1] << " " << primes[i+(primes[i] == n)] << endl;
                break;
            }
        }
    }
}

C++: #include<iostream>
#include<vector>
#define NUM 100000
using namespace std;
int main(){
  int n, prime[NUM], p[NUM],c=0;
  for(int i=0; i<NUM; i++){
   prime[i] = 0;
   p[i] = 0;
  }
  prime[0] = 1;
  for(int i=2; i<=NUM/2; i++){
      for(int j=2; i*j <= NUM; j++){
	if(prime[i*j-1] == 0)
	  prime[i*j-1] = 1;
      }
  }
  
  for(int i=0; i<NUM; i++){
    if(prime[i] == 0){
      p[c] = i+1;
      c++;
    }
  }

  while(cin >> n){
    if(n < 3 || n > 50000) return 0;
    for(int i=0; i<NUM; i++){
      if(n == p[i]){
      	  c=i;
      	  break;
      }
    }
    if(c-1 < 0 || c+1 > NUM) return 0;
    else cout << p[c-1] << " " << p[c+1] << endl;
  }
  return 0;
  
}

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

#define MAX 50010

int main()
{
  bool prime[MAX];
  for (int i = 0; i < MAX; i++) prime[i] = true;
  prime[0] = prime[1] = false;
  for (int i = 2; i < sqrt(MAX); i++){
    for (int j = i * 2; j < MAX; j += i){
      prime[j] = false;
    }
  }

  int n;
  while (cin >> n){
    for (int i = n - 1; i > 0; i--) {
      if (prime[i]) {
        cout << i << ' ';
        break;
      }
    }
    for (int i = n + 1; i < MAX; i++){
      if (prime[i]){
        cout << i << '\n';
        break;
      }
    }
  }
}

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

int main(){
	bool dt[51001];
	int count=0;
	for(int i=1;i<51001;i++){
		for(int j=1;j<5001;j++){
			if(i%j==0)count++;
		}
		if(count==2){dt[i]=true;}
		else{dt[i]=false;}
		count=0;
	}
	int n=0;
	while(cin>>n){
		int i=0;
		int ansf=0,ansl=0;
		for(i=1;i<n;i++){
			if(dt[i]==true){ansf=i;}
		}
		i++;
		while(i>0){
			if(dt[i]==true){ansl=i;i=-10;}
			i++;
		}
		cout<<ansf<<" "<<ansl<<endl;
	}
	return 0;
}