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;

int main()
{
    int prime[30000];
        prime[0] = 2;
    int num = 1, n;

    for(int i=3; i<50100; i++){
        bool f = true;
        for(int j=0; j<num; j++){
            if(i%prime[j] == 0){
                f = false;
                break;
            }
        }
        if(f){
            prime[num] = i;
            num++;
        }
    }

    while(cin >> n, !cin.eof()){

        int i;

        for(i=0; prime[i]<n; i++){
        }
        cout << prime[i-1] << ' ' << ((prime[i] == n) ? prime[i+1] : prime[i]) << endl;
    }

    return 0;
}

C++: #include <stdio.h>

int main(void) {

  int n;
  int np,nm;
  int i,flag;

  while(scanf("%d",&n)!=EOF) {

    np=n+1;
    nm=n-1;
    //printf("%d %d\n",np,nm);
    while(1) {

      flag=1;
      //printf("%d\n",np);
      for(i=2;i<np;i++) {
	if(np%i==0) {
	  flag=0;
	  break;
	}
      }
      //printf("%d\n",flag);
      if(flag==1) break;

      np++;
    }	
    //printf("%d",np);
    while(1) {

      flag=1;
      
      for(i=2;i<nm;i++) {
	if(nm%i==0) {
	  flag=0;
	  break;
	}
      }

      if(flag==1) break;

      nm--;
    }

    printf("%d %d\n",nm,np);

  }
   
  return 0;

}

C++: #include "bits/stdc++.h"
#define int long long
#define range(i, a, b) for(auto i = a; i < b; i++)
#define rep(i, a) range(i, 0, a)
#define all(a) (a).begin(),(a).end()
using namespace std;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const long double EPS = 1e-8;
using vi = vector <int>;
using vvi = vector <vi>;

vector <bool> eratosthenes(int n) {
	vector <bool> prime(n + 1, true);
	prime = vector <bool> (n + 1, true);
	if(n >= 0) prime[0] = false;
	if(n >= 1) prime[1] = false;
	for(int i = 2; i * i <= n; i++)
		if(prime[i])
			for(int j = i * 2; j < n; j += i)
				prime[j] = false;
	return prime;
}


signed main() {
	vector <bool> sosu = eratosthenes(50100);
	int n;
	while (cin >> n) {
		int mini = 0;
		rep (i, n) if (sosu[i]) mini = i;
		cout << mini << " ";
		for (int i = n + 1; ; i++) if (sosu[i]) {
			cout << i << endl;
			break;
		}
	}
	return 0;
}

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

int main(void){
    int table[tablesize];
    for(int i=0;i<tablesize;i++){
        table[i]=1;
    }
    int k;
    table[0]=0;
    table[1]=0;
    for(int i=2;i<(int)sqrt(tablesize)+10;i++){
        if(table[i]==1){
            k=2;
            while(k*i<=tablesize){
                table[k*i]=0;
                k++;
            }
        }
    }

    int n;
    int small, big;
    while(cin>>n){
      for(int i=n-1;i>0;i--){
        if(table[i]==1){
          small=i;
          break;
        }
      }
      for(int i=n+1;i<tablesize;i++){
        if(table[i]==1){
          big=i;
          break;
        }
      }
      cout<<small<<" "<<big<<endl;
    }
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 50100;
int n;
int prime[MAX_N];
bool isPrime[MAX_N+1];
int ptr;
int pos;

int main()
{
  prime[ptr++] = 2;
  for(int i=2; i<=MAX_N; i+=2) isPrime[i] = true;
  for(int i=3; i<=MAX_N; i+=2){
    if(!isPrime[i]){
      prime[ptr++] = i;
      for(int j=2*i; j<=MAX_N; j+=i){
        isPrime[j] = true;
      }
    }
  }

  while((cin >> n) && n){
    pos = upper_bound(prime, prime+ptr, n) - prime;
    cout << (prime[pos-1]==n ? prime[pos-2] : prime[pos-1]) << " " << prime[pos] << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<cmath>
using namespace std;
int x[1000000];
int main() {
	for (int i = 2; i < 1000000; i++) {
		for (int j = 2; j <= sqrt(i); j++) {
			if (i%j == 0) {
				goto E;
			}
		}
		x[i] = 1;
	E:;
	}
	int a, b;
	while (cin >> a) {
		for (int i = a - 1; i >= 0; i--) {
			if (x[i] == 1) { cout << i << ' '; break; }
		}
		for (int i = a + 1; i < 1000000; i++) {
			if (x[i] == 1) { cout << i << endl; break; }
		}
	}
}

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


int main(){
	bool prime[60000];
	for(int i=0;i<60000;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<60000;i++){
		if(prime[i]==1){
			for(int j=i*2;j<60000;j+=i){
				prime[j]=0;
			}
		}
	}
	int n;
	while(cin>>n){
		int i;
		for(i=2;prime[n-i]==0;i--);
		cout<<n-i<<" ";
		for(i=1;prime[n+i]==0;i++);
		cout<<n+i<<endl;
	}
}

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

const int MAXN = 50001;

bool prime[MAXN] = {true, true};

int main()
{
  for (int i = 2; i * i < MAXN; i++){
    for (int j = i * i; j < MAXN; j += i){
      prime[j] = true;
    }
  }

  int n;
  
  while (~scanf("%d", &n)){
    for (int i = n - 1; i >= 3; i--){
      if (!prime[i]){
        printf("%d ", i);
        break;
      }
    }
    for (int i = n + 1; i < MAXN; i++){
      if (!prime[i]){
        printf("%d\n", i);
        break;
      }
    }
  }

  return (0);
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
bool prime[50001];
int main()
{
  for(int i = 2;i <50001;i++){
    prime[i] = true;
  }
  prime[0] = false;
  prime[1] = false;
  for(int j = 2;j <50001;j++){
    if(prime[j]){
      for(int i =2*j;i <50001;i+=j){
	prime[i] = false;
      }
    }
  }
  int x;
  
  while(cin>>x){
 
    for(int i = x-1;i >1;i--){
      if(prime[i]){
	cout << i <<" ";
	break;
      }
    }
    for(int i = x+1;i <50001;i++){
      if(prime[i]){
	cout << i <<endl;
	break;
      }
    }
  }
  return 0;
}