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<cstdlib>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{ 
  const int END = -1;
  const int NUM = 50000;
  int num;
  int i,index,index2,index3;
  
  cin >> num;

  vector<int> eratos(NUM);

  for(i = 0;i < NUM - 1 ; i++)
    eratos[i] = i+2;
  eratos[i] = END;
 
  while(!cin.eof()){
    i = 0;
    index3 = 0;
  while(eratos[i]!=END)
    {
      if(eratos[i]!=0)
        {
          index = i + 1;
          index3 = i + 1;
          while(eratos[index]!=END)
            {
              if(eratos[index]%eratos[i] != 0)
                {
                  eratos[index3] = eratos[index];
                  index3++;
                }
              index++;
            }
          eratos[index3] = END;
        }
      i++;
    }
 
  for(i = 0; i < index3; i++)
    {
      if(eratos[i]==num)
        {
          cout << eratos[i-1] << " " << eratos[i+1] << endl;
          break;
        }
      else if(eratos[i] > num)
        {
          cout << eratos[i-2] << " " << eratos[i] << endl;
          break;
        }
    }
    cin >> num;
  }
  return 0;
}

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

/** Problem0044 : Prime Number II **/
#define MAX 51000
int main()
{
	bool prime[MAX];
	int  input;
	
	for (int i=0; i<MAX; i++)
		prime[i] = true;
	
	prime[0] = false; prime[1] = false;
	
	for (int i=2; i<MAX; i++) {
		if (prime[i]) {
			for (int j=2; i*j<MAX; j++) {
				prime[i*j] = false;
			}
		}
	}
	
	while (cin >> input) {
		for (int i=input-1; i>1; i--) {
			if (prime[i]) {
				cout << i << " ";
				break;
			}
		}
		
		for (int i=input+1; i<51000; i++) {
			if (prime[i]) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

C++: /*****include*****/
#include <iostream>
#include <fstream>

/*****デバッグ定義*****/
//#define DEBUG
/*****マクロ定義*****/

/*****名前空間*****/
using namespace std;

/*****グローバル変数置き場*****/

/*****その他関数置き場*****/
bool isPrime(unsigned int number){
	if(number == 1)	return false;
	for(int i=2;i*i <= number;i++){
		if(number % i == 0){
			return false;
		}
	}
	return true;
}
/*****main関数*****/
int main(){
	/*****ファイルオープン*****/
#ifdef DEBUG
	ofstream fout("output.txt");
	ifstream fin("input.txt");
	if(!fout || !fin){
		cout << "Can't open the file.\n";
		return;
	}
#endif
	/*****変数置き場*****/
	
	
	
	/*****処理部*****/
	unsigned int number;
	unsigned int i;
	unsigned int j;
	while(1){
		cin >> number;
		for(i=number-1;i>=0;i--){
			if(isPrime(i))	break;
		}
		for(j=number+1;j>0;j++){
			if(isPrime(j))	break;
		}
		cout << i << " " << j << endl;
	}
	/*****処理終了後*****/
#ifdef DEBUG
	fout.close();
	fin.close();
#endif
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cmath>

#define NMAX 50000+100
#define YES 0
#define NO 1

using namespace std;

int main(void){

	int hurui[NMAX]={YES};

	hurui[0]=NO,hurui[1]=NO;
	for(int i=2;i<sqrt((double)NMAX);i++){
		if(hurui[i]==YES){
			for(int j=i+i;j<NMAX;j+=i){
				hurui[j]=NO;
			}
		}
	}

	int inp;

	while(cin>>inp){
		for(int i=inp-1;;i--){
			if(hurui[i]==YES){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=inp+1;;i++){
			if(hurui[i]==YES){
				cout<<i<<endl;
				break;
			}
		}
	}

	return 0;
}

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

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
//is(string &s){int c;
//	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
//void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

unsigned long powm(int b, int n, int m) {
	if (n == 0)
		return 1;
	else if (n == 1)
		return b % m;
	unsigned long t = powm(b, n / 2, m);
	return t * t % m * (n % 2 ? b : 1) % m;
}


bool fermat(int n) {
	for (int i = 0; i < log(n) * 3; i++) {
		int r = rand();
		if (r % n && powm(r, n - 1, n) != 1)
			return false;
	}
	return true;
}

bool is_prime(int n) {
	return fermat(n);
}

int main() {
	for (int n; scan(n);) {
		for (int i = n - 1;; i--)
			if(is_prime(i)) {
				out(i, ' ');
				break;
			}
		for (int i = n + 1;; i++)
			if(is_prime(i)) {
				out(i, '\n');
				break;
			}
	}
}

C++: #include <iostream>
#include <bitset>
#include <cstdio>

using namespace std;

int main()
{
  bitset<60000> is_prime;
  is_prime.set();
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i <= 60000; i++) {
    for (int j = i + i; j  <= 60000; j += i) {
      is_prime[j] = false;
    }
  }

  int N;
  while (scanf("%d ", &N) == 1) {
    int d_m, u_m;
    for (int i = N - 1;; i--) {
      if (is_prime[i]) {
	d_m = i;
	break;
      }
    }
    for (int i = N + 1;; i++) {
      if (is_prime[i]) {
	u_m = i;
	break;
      }
    }
    printf("%d %d\n", d_m, u_m);
  }
  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>

inline bool isp(int n) {
    int ed = (int) sqrtf((float) n);
    for (int i = 2; i <= ed; ++i) {
        if (!(n % i)) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;

    while (scanf("%d", &n) != EOF) {
        int mx = 0;
        int mi = 0;

        for (int i = n - 1; 1 < i; --i) {
            if (isp(i)) {
                mx = i;
                break;
            }
        }

        for (int i = n + 1; i < 50000; ++i) {
            if (isp(i)) {
                mi = i;
                break;
            }
        }

        printf("%d %d\n", mx, mi);
    }

    return 0;
}

C++: #include <stdio.h>
#include <math.h>
#define N 50060

void Eratos(void);

int prime[N];

int main(void){
	int n;
	int lessmax, bigmin;

	Eratos();

	while(scanf("%d", &n) != EOF){
		for(int i=n-1;; i--){
			if(prime[i] == 1){
				lessmax = i;
				break;
			}
		}
		for(int i=n+1;; i++){
			if(prime[i] == 1){
			   	bigmin = i;
				break;
			}
		}

		printf("%d %d\n", lessmax, bigmin);
	}

	return 0;
}

void Eratos(void){
	for(int i=0; i<N; i++){
		prime[i] = 1;
	}
	prime[0] = prime[1] = 0;

	for(int i=2; i <= sqrt(N); i++){
		for(int j=2; i*j < N; j++){
			prime[i*j] = 0;
		}
	}
}