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;

const int MAX_P = 50025;
bool p[MAX_P];  // prime table

void init()
{
    for (int i = 0; i < MAX_P; i++)
        p[i] = true;

    p[0] = p[1] = false;
    for (int i = 2; i * i < MAX_P; i++) {
        if (p[i]) {
            for (int j = i * 2; j < MAX_P; j += i)
                p[j] = false;
        }
    }
}

int main()
{
    int n;

    init();

    while (cin >> n) {
        int min, max;

        min = max = n;
        while (--min >= 2) 
            if (p[min])
                break;
        while (++max <= MAX_P) 
            if (p[max])
                break;

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

    return 0;
}

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

bool prime[MAX];
void calcPrime(){
	for(int i = 0; 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;

/*テァツエツ?ヲツ閉ーテ・ツ按、テ・ツョツ?/
const int MAX = 1000100;
bool prime[MAX];

void sieve(){
	fill(prime, prime+MAX, true);
	prime[0] = prime[1] = false;

	for(int i=2; i*i < MAX; i++){
		if(!prime[i]) continue;
		for(int j=i*i; j < MAX; j += i) prime[j] = false;

	}

}


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

C++: 
#include<iostream>
using namespace std;
int prime[100000];
int main()
{
  prime[0] = prime[1] = 2;
  for(int i = 2; i < 100000; i++)
  {
    if(prime[i])
      continue;
    for(int j = i + i; j < 100000; j += i)
      prime[j] = 2;
  }
  int n;
  while(cin >> n)
  {
    int i;
    for(i = n - 1; prime[i] == 2; i--);
    cout << i << " ";
    for(i = n + 1; prime[i] == 2; i++);
    cout << i << endl;
  }
}

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

int main() {
  bool p[50001];
  int n, x;

  memset(p, 0, sizeof(bool)*50001);
  for (int i=2; i*i<=50000; i++) {
    if (!p[i]) {
      for (int j=2*i; j<=50000; j+=i) {
        p[j] = true;
      }
    }
  }
  while (scanf("%d", &n) == 1) {
    x = n-1;
    while (p[x]) --x;
    printf("%d ", x);
    x = n+1;
    while (p[x]) ++x;
    printf("%d\n", x);
  }
  return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

void sieve(bool* a){
	for(int i=2;i<=sqrt(50100.);++i){
		if(a[i]){
			for(int j=i*2;j<=50100;j+=i){
				a[j]=false;
			}
		}
	}
}

int main(){
	int n;
	bool a[50101];
	memset(a , true , sizeof(a));
	a[0]=a[1]=false;
	sieve(a);
	while(cin>>n){
		int i,j;
		for(i=n-1;i>=2;--i){
			if (a[i]==true) break;
		}
		for(j=n+1;j<=50101;++j){
			if(a[j]==true) break;
		}
		cout << i << " " << j << endl;
	}
	return 0; 
}

C++: #include<iostream>
#include<cmath>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;

const int M = 50000;
bool prime[M];

void isPrime(){
    fill(prime, prime + M, true);
    prime[0] = prime[1] = false;
  
    for(int i = 2; i < M; i++) {
        if(prime[i])
        for(int j = 2; i*j < M ; j++) {
            prime[i*j] = false;
        }
    }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n){
    long long int i = n - 1;
    while(!prime[i])i--;
    cout<<i<<" ";
    i = n + 1;
    while(!prime[++i]);
    cout<<i<<endl;
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
bool prime[50001];

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

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

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

int main() {
	bool prime[55001] = { false };
	for (int i = 2; i <= sqrt(55000); i++) {
		if (!prime[i]) {
			for (int j = 2; i*j <= 55000; j++) {
				prime[i*j] = true;
			}
		}
	}
	int n;
	while (cin >> n) {
		for (int i = n-1;; i--) {
			if (!prime[i]) {
				cout << i << " ";
				break;
			}
		}
		for (int i = n+1;; i++) {
			if (!prime[i]) {
				cout << i << endl;
				break;
				}
			}
		}
}

C++: #include "bits/stdc++.h"

using namespace std;
 
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

bool era[60000];

void makeERA(){
	for(int i=0;i<60000;i++){
		if(era[i]==true){
			for(int j=2;j*i<60000;j++){
				era[j*i]=false;
			}
		}
	}
}


int main(){
	for(int i=2;i<60000;i++){
		era[i]=true;
	}

	makeERA();


	vector<int> prime;

	for(int i=0;i<60000;i++){
		if(era[i]==true)prime.push_back(i);
	}


	int n;
	while(cin>>n){
	
		for(int i=0;i<prime.size();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;
			}
		}
	}
	return 0;
}

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

int a[100000];

void sosuu() {
	a[0] = 2;
	int k, z = 1;
	for (int i = 3; i<100000; i++) {
		k = 0;
		for (int j = 0; a[j] <= sqrt(i); j++) {
			if (i%a[j] == 0) {
				k++;
				break;
			}
		}
		if (k == 0) {
			a[z] = i;
			z++;
		}
	}
	return;
}

int nibun(int n, int s, int e){
	if (s >= e) return s;
	if(a[(s + e)/2] < n){
		if(a[(s+e)/2 + 1]>n ){
			return (s + e) / 2;
		}
		return nibun(n, (s + e) / 2 + 1, e);
	}
	else if(a[(s + e) / 2] > n){
		return nibun(n, s, (s + e) / 2 - 1);
	}
	else return (s + e) / 2;
}


int main(){
	sosuu();
	int n, k;
	while(cin >> n){
		int ret = nibun(n, 0, 10000);
		if(n == a[ret]){
			cout << a[ret - 1] << " " << a[ret + 1] << endl;
		}

		else cout << a[ret] << " " << a[ret + 1] << endl;
	}
	return 0;
}