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 ;

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int arr[100001];
void Eratosthenes(int N){
  for(int i = 0; i < N; i++){
    arr[i] = 1;
  }
  arr[1] = 0;
  for(int i = 2; i*i < N ; i++){
    if(arr[i]){
      for(int j = 0; i * (j + 2) < N; j++){
        arr[i *(j + 2)] = 0;
      }
    }
  }
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  Eratosthenes(50000);
  int n;
  while(cin >> n){
    for(int i = n-1; i > 1; --i){
      if(arr[i] == 1){
        cout << i ;
        break;
      }
    }
    for(int i = n+1; i < 50001; ++i){
      if(arr[i] == 1){
        cout << " " << i << endl;
        break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>

using namespace std;

bool prime_table[5001];
int n;

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

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

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

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

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

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

C++: #include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <iostream>


using namespace std;


vector<int> CreatePrimes(int n)
{
	bool* work = new bool[n+1];

	fill(work, work+(n+1), true);
	work[0] = work[1] = false;

	vector<int> res;
	res.push_back(2);
	for (int i = 4; i <= n; i += 2)
		work[i] = false;

	for (int i = 3; i <= n; i += 2)
	{
		if (work[i])
		{
			res.push_back(i);
			for (int j = 2*i; j <= n; j += i)
				work[j] = false;
		}
	}

	delete[] work;

	return res;
}

int main()
{
	int n;
	vector<int> primes = CreatePrimes(100000);
	while (scanf("%d", &n) != EOF)
	{
		vector<int>::iterator it = lower_bound(primes.begin(), primes.end(), n);
		printf("%d %d\n", *(it-1), *(it+1));
	}

	return 0;
}

C++: #include<iostream>
using namespace std;
int isPrime[60001];
void prime(){
  for(int i=0;i<60001;i++)isPrime[i]=1;
  isPrime[0]=isPrime[1]=0;
  for(int i=4;i<60001;i+=2)isPrime[i]=0;
  for(int i=3;i*i<=60001;i++){
    if(isPrime[i]){
      for(int j=i+i;j<60001;j+=i)isPrime[j]=0;
    }
  }
}

int main(){
  int a;
  prime();
  while(cin>>a){
    for(int i=a-1;i>=2;i--){
      if(isPrime[i]){
	cout<<i<<' ';
	break;
      }
    }
    for(int i=a+1;i<=60000;i++){
      if(isPrime[i]){
	cout<<i<<endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int prime[50002];
  prime[0] = prime[1] = 0;
  for(int i = 2 ; i < 50001 ; i++)prime[i] = 1;

  for(int i = 2 ; i*i < 50001 ; i++){
    if(prime[i] == 1 ){
      for(int j = i*2 ; j < 50001 ; j+=i)prime[j] = 0;
    }
  }

  int n;
  while(cin >> n){
    int ans_M,ans_m;

    for(int i = n-1 ;; i-- ){
      if(prime[i]){
	ans_m = i;break;
      }
    }
    for(int i = n+1 ;; i++ ){
      if(prime[i]){
	ans_M = i;break;
      }
    }
    cout << ans_m<<" "<<ans_M<<endl;

  }
}

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


bool isPrime(int n){
    if(n == 2) return true;
    if(n % 2 == 0) return false;

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

int main() {

    int input;
    
    while(cin >> input){
        for (int i = 1; i < 100; ++i)
            if(isPrime(input - i)){
                cout << (input - i) << " ";
                break;
            }

        for (int j = 1; j < 100; ++j)
            if(isPrime(input + j)){
                cout << (input + j) << endl;
                break;
            }

    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N (50500)

bool prime[N + 1];

int main()
{
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	
	for (int i = 2; i * i <= N; i++){
		for (int j = i * i; j <= N; j += i){
			prime[j] = false;
		}
	}
	
	int n;
	while (~scanf("%d", &n)){
		int l = n - 1;
		while (!prime[l]) l--;
		int r = n + 1;
		while (!prime[r]) r++;
		printf("%d %d\n", l, r);
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

int main()
{
	int prnum[50022] = { 0 }, n;

	for (int i = 2; i < 50022; i++) {
		if (!(prnum[i])) {
			for (int j = i*2; j < 50022; j+=i) {
				prnum[j] = 1;
			}
		}
	}

	while (1) {
		cin >> n;
		if (cin.eof()) break;

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

}

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

vector<int> prime;

int main(void) {
	for(int i = 2;i < 60000;i++) {
		bool isPrime = true;
		for(auto e:prime) {
			if(i % e == 0) {
				isPrime = false;
				break;
			}
		}
		if(isPrime) prime.push_back(i);
	}
	int n;
	while(cin >> n) {
		auto eq = equal_range(prime.begin(),prime.end(),n);
		cout << *(eq.first-1) << " " << *(eq.second) << endl;
	}
}