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 <bits/stdc++.h>
using namespace std;

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool* PrimeSieve(int n) {
  bool*s = new bool[n];
  for (int i = 0; i < n; ++i) s[i] = true;
  s[0] = s[1] = false;
  for (int i = 2; i < n; ++i)
    if (s[i]) for (int j = 2 * i; j < n; j += i) s[j] = false;
  return s;
}

int main() {

  const int N = 50022;
  auto isprime = PrimeSieve(N);

  loop {
    int n; cin >> n;
    if (!cin) break;
    int a,b;
    for (int m = n-1; m > 0; --m) {
      if (isprime[m]) {
        a = m;
        break;
      }
    }
    for (int m = n+1; m < N; ++m) {
      if (isprime[m]) {
        b = m;
        break;
      }
    }
    cout << a << ' ' << b << endl;
  }

  return 0;
}

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

int main(){
  int table[55000]={};
  for(int i=2; i*i<55000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=55000; j+=i){
        table[j]=1;
      }
    }
  }

  int n;
  while(1){
    int i;
    for(i=n-1; table[i]; --i);
    cout << i << " ";
    for(i=n+1; table[i]; ++i);
    cout << i << endl;
  }
  return 0;
}

C++: #include <iostream>
#define r(i,n) for(int i=0;i<n;i++)
int a[51000];
using namespace std;
int main(){
  for(int i=2;i<51000;i++){
    for(int j=i*2;j<51000;j+=i)a[j]++;
  }
  int n;
  while(cin>>n){
    for(int i=n-1;i>=2;i--)if(!a[i]){cout<<i<<' ';break;}
    for(int i=n+1;i<=51000;i++)if(!a[i]){cout<<i<<endl;break;}
  }
}

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

int main(){
  bool a[1000000];

  a[0]=a[1]=false;
  for(int i=2;i<1000000;i++){
    a[i]=true;
  }

  for(int i=2;i*i<1000000;i++){
    if(a[i]){
      for(int j=i*i;j<1000000;j+=i){
        a[j]=false;
      }
    }
  }

  int min,max;

  while(true){
    int m;
    cin>>m;

    if(cin.eof()){
      break;
    }

    for(int i=3;i<=m;i++){
      if(a[i]){
        max=i;
      }
    }
    for(int i=m+1;i<1000000;i++){
      if(a[i]){
        min=i;
        break;
      }
    }

    cout<<max<<' '<<min<<endl;

  }

  return 0;
}

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

int main(){
  bool is_prime[100000];

  is_prime[0] = is_prime[1] = false;
  for(int i=2; i<100000; i++){
    is_prime[i] = true;
  }

  for(int i=2; i*i<100000; i++){
    if(is_prime[i]){
      for(int j=i*i; j<100000; j+=i){
	is_prime[j] = false;
      }
    }
  }

  while(true){
    int n;
    cin >> n;

    if(cin.eof())
      break;

    for(int i=n-1; i>=2; i--){
      if(is_prime[i]){
	cout << i << ' ';
	break;
      }
    }
    for(int i=n+1; i<=60000; i++){
      if(is_prime[i]){
	cout << i << endl;
	break;
      }
    }
  }

  return 0;
}

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

int main(void){
  bool prime[MAX] = {false};

  prime[0] = prime[1] = true;
  for(int i = 2 ; i*i <= MAX-1 ; i++){
    if(!prime[i]){
      for(int j = i*2 ; j <= MAX - 1 ; j += i){
        prime[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;
      }
    }
  }

  return 0;
}

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

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;
		}
	}
}

C++: #include <stdio.h>
int main(){
    int n,i,f[10000],now=2;
    bool flag;
    f[0]=2;
    f[1]=3;
    for(i=5;i<60000;i+=2){
        flag=true;
        for(int j=1;f[j]*f[j]<=i&&flag;j++){
            if(i%f[j]==0)flag=false;
        }
        if(flag){
            f[now]=i;
            now++;
        }
    }
    while(scanf("%d",&n)!=EOF){
        for(i=0;f[i]<n;i++);
        if(f[i]==n)printf("%d %d\n",f[i-1],f[i+1]);
        else printf("%d %d\n",f[i-1],f[i]);
    }
}

C++: #include<iostream>
using namespace std;
int isPrime(int n){
  for(int i=2;i*i<=n;i++) if(n%i==0) return false;
  return true;
}
int main(){
  bool d[70000];
  for(int i=0;i<70000;i++) d[i]=isPrime(i);
  int n;
  while(cin >> n){
    int k=1;
    while(!d[n-k]) k++;
    cout << n-k << " ";
    k=1;
    while(!d[n+k]) k++;
    cout << n+k << endl;
  }
}

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

int main()
{
    int n;
    int max,first;
    bool flag=false;
    while(cin>>n,!cin.eof()){
        for(int i=2;i<n;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i/2<j){
                    max=i;
                    break;
                }
            }
        }
        if(n==3){
            max=2;
        }
        cout<<max<<' ';
        bool flag=false;
        for(int i=n+1;;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i/2<j){
                    first=i;
                    flag=true;
                    break;
                }
            }
            if(flag)break;
        }
        cout<<first<<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <cstring>
using namespace std;
int main(){
	int n,m;
	bool f[50001];
	memset(f,true,sizeof(f));
	for(int i=2;i<50001;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				f[i]=false;
				break;
			}
		}
	}
	while(cin>>n){
		for(int i=n-1;i>2;i--){
			if(f[i]){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=n+1;i<50001;i++){
			if(f[i]){
				cout<<i<<endl;
				break;
			}
		}
	}
	return 0;
}