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 prime[60001];

int main(void) {
  for (int i = 0; i <= 60000; i++) {
    prime[i] = true;
  }
  prime[0] = prime[1] = false;

  for (int i = 2; i <= 60000; i++) {
    if (prime[i]) {
      for (int j = 2; i * j <= 60000; j++) {
	prime[i*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 <= 60000; i++) {
      if (prime[i]) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#define NUM 1000000
using namespace std;
int main(){
  int n, prime[NUM];
  vector<int> p;
  for(int i=0; i<NUM; i++) prime[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.push_back(i+1);
  }

  while(cin >> n){
    vector<int>::iterator it = p.begin();
    while(it != p.end()){
      if(n == *it)
	cout << *(it-1) << " " << *(it+1) << endl;
      it++;
    }
  }
  
}

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++: // clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

constexpr bool isPrime(const int &n) {
  if (n == 1) return false;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}

void solve() {
  int n;
  while (cin >> n) {
    int l = n - 1, r = n + 1;
    while (!isPrime(l)) l--;
    while (!isPrime(r)) r++;
    cout << l << ' ' << r << endl;
  }
}

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

const int SIZE = 50001;

int main(int argc, char *argv[]) {
	// make sieve
	vector<bool> sieve(SIZE, true);
	vector<int> prime;
	for (int i = 2; i < SIZE; i++) {
		if (sieve[i]) {
			prime.push_back(i);
			//printf("%d\n", i);
			for (int j = i+i; j < SIZE; j+=i) {
				sieve[j] = false;
			}
		}
	}
	sort(prime.begin(), prime.end());
	// load data
	int rcv;
	const int prime_size = static_cast<int>(prime.size());
	while (EOF != fscanf(stdin, "%d", &rcv)) {
		for (int i = 0; i < prime_size; i++) {
			if (prime[i] > rcv) {
				if (prime[i-1] != rcv)
					printf("%d %d\n", prime[i-1], prime[i]);
				else
					printf("%d %d\n", prime[i-2], prime[i]);
				break;
			}
		}
	}
	return 0;
}

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

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

	int n;

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

	return 0;
}

C++: #include <iostream>

using namespace std;

int prime(int n)
{
	if(n < 2){
		return 0;
	} else if(n == 2){
		return 1;
	}
	
	if(n % 2 == 0){
		return 0;
	}
	
	for(int i = 3; i*i <= n; i+= 2){
		if(n % i == 0){
			return 0;
		}
	}
	
	return 1;
}

int main(int argc, char **argv)
{
	int n, s, t;
	
	while(cin >> n){
		for(int i = n-1; i >= 2; i--){
			if(prime(i) == 1){
				s = i;
				break;
			}
		}
		for(int i = n+1; i <= 60000; i++){
			if(prime(i) == 1){
				t = i;
				break;
			}
		}
		
		cout << s << " " << t << endl;
	}
	
	return 0;
}

C++: #include<iostream>
#include<map>

using namespace std;

bool sosu(long int n)
{
	for(int i=2;i*i<=n;i++)
	{
		if(n%i==0)return false;
	}
	return true;
}

int main(void)
{
	long int n;
	while(cin>>n)
	{
		long int l,s;
		l=s=n;
		l++;s--;
		bool lf,sf;
		lf=sf=true;
		while(1)
		{
			if(lf)
			{
				if(sosu(l)) lf=false;
				else l++;
			}
			if(sf)
			{
				if(sosu(s)) sf=false;
				else s--;
			}
			if(lf==false&&sf==false) break;
		}
		cout<<s<<' '<<l<<endl;
	}
}

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

int main(){
  int n;
  while(cin >> n,n){
    for(int i=n-1; i>0; --i){
      bool frg = true;
      for(int j=2; j*j<i; j+=2){
        if(i%2==0){frg=false; break;}
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i;break;}
    }
    
    cout << " ";
    
    for(int i=n+1; i<2*n ; ++i){
      bool frg = true;
      for(int j=2; j*j<i; j+=2){
        if(i%2==0){frg=false; break;}
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i << endl;break;}
    }
    
  }
  return 0;
}