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<cstdio>
#include<algorithm>
#include<iterator>
#include<vector>
using namespace std;
#define int long long
signed main(){
	vector<int> primes(50050,1);
	for(int i=2;i<230;i++){
		if(primes[i]==0) continue;
		for(int j=i+1;i<50050;i++){
			if(j%i==0) primes[j] = 0;
		}
	}
	int a;
	while( scanf("%lld", &a) != EOF ){
		for(int i=0;i<50050;i++){
			if(primes[i]>a){ cout << primes[i-1] << " " << primes[i] << endl; break;}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef vector <int> vi;
#define REP1(i,n1,n2) for (int i=n1; i<n2; i++)
vi primes;

int get_primes(int m){
    int n = (m+1)/2, root = (int)(pow(n, 0.5));
    vector <bool> N(n, true);
    N[0]=false;

    if (m>1) primes.push_back(2);
    REP1(i,1,root){
        int tmp = i*2+1;
        if (N[i]){
            primes.push_back(tmp);
            for (int j=i+tmp; j<n+1; j+=tmp)
				N[j]=false;
        }
    }
    REP1(i,root,n+1)
        if(N[i]) primes.push_back(2*i+1);
    return 0;
}

int main(){
	get_primes(50100);
	while (true){
		int n,a,b;
		cin>>n;
		if (cin.eof()) break;
		REP1(i,0,(int)primes.size()){
			a=primes[i];
			if (a<n) b=a;
			else if (a>n) break;
		}
		cout<<b<<" "<<a<<endl;
	}
}

C++: def create_prime(n):
    prime = [1] * (n + 1)
    prime[:2] = [0, 0]
    for i in range(len(prime)):
        if prime[i]:
            for j in range(2 * i, len(prime), i):
                prime[j] = 0
    return prime

def under(prime, n):
    for i in range(n - 1, -1, -1):
        if prime[i]:
            return i
def over(prime, n):
    for i in range(n + 1, len(prime)):
        if prime[i]:
            return i
        

import sys

n = [int(line) for line in sys.stdin]

prime = create_prime(max(n) + 100)

for ni in n:
    print(under(prime, ni), over(prime, ni))

C++: #include <iostream>
#include <vector>
using namespace std;
#define MAX 100001

bool prime[MAX];
void calcPrime(){
	for(int i = 2; i < MAX; i++) prime[i] = true;
	for(int i = 2; i < MAX; i++){
		if( prime[i] ){
			for(int j = i+i; j < MAX; j += i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	int n;
	calcPrime();
	while( cin >> n ){
		int under = -1, over = -1;
		for(int d = n, u = n; 2 < d || u < MAX; ){
			if( 2 < d ) d--;
			if( u < MAX ) u++;
			if( under != -1 && over != -1 ) break;
			if( prime[d] ) under = d;
			if( prime[u] ) over = u;
		}
		cout << under << " " << over << endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(){
  bool num[1000001]={false};
  for(int i=2; i<1000; i++) if(!num[i]) for(int j=i*i; j<1000001; j+=i) num[j] = true;
  for(int n; cin >>n;){
    for(int i=n-1;;i--) if(!num[i]){cout <<i<<" ";break;}
    for(int i=n+1;;i++) if(!num[i]){cout <<i<<endl;break;}
  }
  return 0;
}

C++: #include <iostream>
#include <math.h>

#define N 50050

using namespace std;

int main(void){
	bool isprime[N];
	for(int i=0;i<N;i++) isprime[i]=true;
	int upto = (int)sqrt(N);
	for(int i=2;i<=upto;i++){
		if(isprime[i]){//消されてなければその倍数を消す
			for(int j=2;i*j<=N;j++) isprime[i*j] = false;
		}
	}
	int n;
	while(cin >> n){
		int prm1,prm2;
		for(int i=n-1;i>1;--i){
			if(isprime[i]){
				prm1 = i;
				break;
			}
		}
		for(int i=n+1;i<N;++i){
			if(isprime[i]){
				prm2 = i;
				break;
			}
		}
		cout << prm1 << " " << prm2 << "\n";
	}
	return 0;
}

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



bool judgePrimenum(int n){

	int sqr = sqrt((double)n);

	if(n%2 == 0)return false;

	for(int i=3;i<=sqr;i+=2){
		if(n%i == 0)return false;
	}

	return true;
}




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

		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<bits/stdc++.h>

using namespace std;

int main(){

  vector<int> arr(100000);

  for(int i=0;i<100000;++i)
	arr[i] = 1;

  for(int i=2;i<sqrt(100000);++i){
	if(arr[i]){
	  for(int j = 0;i*(j+2) < 100000; j++)
		arr[i*(j+2)] = 0;
	}
  }

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

	for(int i=n+1;i<=100000;++i){
	  if(arr[i]==1){
		cout<<i<<endl;
		break;
	  }
	}
	
  }	
}

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
set<int> primes={2,3,5,7,11,13,17,19,23,29,31,37,
                 41,43,47,53,59,61,67,71,73,79,
                 83,89,97,101,103,107,109,113,127,131,
                 137,139,149,151,157,163,167,173,179,181,
                 191,193,197,199,211,223,227};
bool isPrime(int n){
  for(int p:primes){
    if(p*p>n)return true;
    if(n%p==0)return false;
  }
  return true;
}
int main(){
  for(int i=229;i<50040;i+=2)
    if(isPrime(i))
      primes.insert(i);
  int n;
  while(cin>>n){
    auto r=primes.lower_bound(n);
    auto l=r;
    if(primes.count(n)==1){
      r++;l--;
    }
    else{
      l--;
    }
    cout<<(*l)<<" "<<(*r)<<endl;
  }
}

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

vector<int> primes;
bool is_prime[100010];

void calc_prime(int n){
	for(int i = 0; i <= n; ++i)
		is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	
	for(int i = 2; i <= n; ++i){
		if(is_prime[i]){
			primes.push_back(i);
			for(int j = i * 2; j <= n; j += i)
				is_prime[j] = false;
		}
	}
}

int main() {
	calc_prime(100000);
	int n;
	while(cin >> n){
		auto it = lower_bound(primes.begin(), primes.end(), n);
		cout << *(it - 1) << " " << *(it + 1) << endl;
	}
	return 0;
}

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

bool prime(int n) {
	switch (n) {
	case 1: return false;
	case 2: return true;
	case 3: return true;
	}
	if (n % 2 == 0 || n % 3 == 0) return false;
	if (n % 6 != 1 && n % 6 != 5) return false;
	for (int i = 5; i * i <= n; i += 6) {
		if (n % i == 0) return false;
		if (n % (i + 2) == 0) return false;
	}
	return true;
}

int main() {
	int n;
	while (cin >> n) {
		int sn = 0;
		int bn = 0;
		if (n % 2 == 0) {
			for (int i = 1;; i += 2) {
				if (sn == 0 && prime(n - i) == true) sn = n - i;
				if (bn == 0 && prime(n + i) == true) bn = n + i;
				if (sn != 0 && bn != 0) break;
			}
		}
		else {
			for (int i = 2;; i += 2) {
				if (sn == 0 && prime(n - i) == true) sn = n - i;
				if (bn == 0 && prime(n + i) == true) bn = n + i;
				if (sn != 0 && bn != 0) break;
			}
		}
		cout << sn << " " << bn << endl;

	}
	return 0;
}