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(){
  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>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 1000000
int p[N];
int main() {
	int i, j,n,cnt;
	for (i = 2; i <= sqrt(N); i++) if (!p[i]) for (j = i*i; j < N; j += i)p[j] = 1;
	while (cin >> n) {
		for (i = n - 1;; i--) if (!p[i]) { cout << i<<" "; break;}
		for (i = n + 1;; i++) if (!p[i]) { cout << i << endl; break; }
	}
	return 0;
}

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

using namespace std;

int main(void){
  int prime[50000];
  int prime_f[50001];
  int k;
  int n;
  int i,j;
  int n_size;

  while(cin>>n){
    k=0;
    memset(prime_f,0,sizeof(prime_f));
    prime_f[0]=prime_f[1]=1;
    for(i=2;i<50000;i++){
      if(!prime_f[i]){
	k++;
	prime[k]=i;
	for(j=2*i;j<50000;j+=i){
	  prime_f[j]=1;
	}
      }
    }

    for(i=0;i<k;i++){
      if(prime[i]>=n){
	printf("%d %d\n",(prime[i]>=n)? prime[i-1]:prime[i],prime[i+1]);
	break;
      }  
    }
  }
  return(0);
}

C++: #include<string>
#include<vector>
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<functional>
#include<algorithm>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include<ctime>
#include<complex>

using namespace std;

#define REP(i,s,e) for(int i=int(s);i<=int(e);i++)
#define rep(i,n) for(int i=0;i<int(n);i++)


bool f(int n){
	int p;
	REP(i,2,n){
	if(n%i==0){
	p=i;
	break;
	}
	}
	if(p==n) return true;
	else return false;
}

int main(){

	int n;
	while(cin >> n){

	int p1,p2;

	for(int i=n+1;;i++){
	if(f(i)){ p1=i; break;}

	}

	for(int i=n-1;;i--){
	if(f(i)){ p2=i; break;}

	}

	cout << p2 << " " << p1 << endl;

	}

	return 0;
}

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

int main() {
	bool prime[100000];
	fill(prime, prime + 100000, 1);
	prime[0] = prime[1] = false;
	for (int i = 2; i * i < 100000; i++) {
		for (int j = 2; i * j < 100000; j++) {
			if (!prime[i * j]) continue;
			prime[i * j] = false;
		}
	}

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

C++: #include <iostream>
using namespace std;
bool num[50021];
int main()
{
	int n;
	while(cin >> n)
	{
		num[0]=num[1]=true; for(int i=2;i<=n;i++) num[i]=false;
		int ansup,anslow;
		for(int i=2;i<=50000;i++)
		{
			if(num[i]==false)
			{
				for(int j=i*2;j<=50021;j+=i) num[j]=true;
			}
		}
		for(int j=n+1; ;j++) if(num[j]==false) {ansup=j; break;}
		for(int j=n-1; ;j--) if(num[j]==false) {anslow=j; break;}
		cout << anslow << ' ' << ansup << '\n' ;
	}
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define X real()
#define Y imag()
#define value(x,y,w,h) (x >= 0 && x < w && y >= 0 && y < h)
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using comd = complex<double>;
using pii = pair<int,int> ;

constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

double CalcDist(comd p1, comd p2){
  return sqrt(pow(p1.X - p2.X,2.0) + pow(p1.Y -p2.Y,2.0));
}

template <typename T>
void out(deque < T > d)
{
  for(size_t i = 0; i < d.size(); i++)
  {
    debug(d[i]);
  }
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

int arr[100001];
void Eratosthenes(int N){
  for(int i = 0; i < N; i++){
    arr[i] = 1;
  }
  arr[1] = 0;
  for(int i = 2; i*i < N ; i++){
    if(arr[i]){
      for(int j = 0; i * (j + 2) < N; j++){
        arr[i *(j + 2)] = 0;
      }
    }
  }
}


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N = 50100;
  Eratosthenes(N);
  int n;
  while(cin >> n){
    for(int i = n-1; i > 1; --i){
      if(arr[i] == 1){
        cout << i ;
        break;
      }
    }
    for(int i = n+1; i < N; ++i){
      if(arr[i] == 1){
        cout << " " << i << endl;
        break;
      }
    }
  }
  return 0;
}

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

bool Prime(int in){
	for (int i = 3; i <= sqrt(in); i += 2){
		if (in%i == 0)	return false;
	}
	return true;
}

vector<int> kakunou(vector<int> in){
	in.push_back(2);
	in.push_back(3);

	for (int i = 5; i < 51000; i += 2){
		if (Prime(i))	in.push_back(i);
	}
	return in;
}

int main(){
	int in;
	vector<int> vec;

	vec = kakunou(vec);

	while (cin >> in, !cin.eof()){
		vector<int>::iterator it = vec.begin();
		while (1){
			if (*it >= in){
				--it;
				cout << *it << " ";
				++it;
				if (*it == in)	++it;
				cout << *it << endl;
				break;
			}
			++it;
		}
	}

	return 0;
}

C++: #include <iostream>
#include <algorithm>
 
using namespace std;
 
bool isPrime[60000];
 
int main(void){
  fill(isPrime, isPrime+60000, true);
  for(int i=2;i<60000;i++){
    if(isPrime[i]){
      for(int j=2; i*j<60000;j++){
	isPrime[i*j] = false;
      }
    }
  }
 
  int n;
  while(cin >> n){
    int tmp=1;
    int mini=0, maxi = 0;
    while(1){
      if(mini == 0 && isPrime[n-tmp] == true) mini = n-tmp;
      if(maxi == 0 && isPrime[n+tmp] == true) maxi = n+tmp;
      if(mini != 0 && maxi != 0) break;
      tmp++;
    }
    cout << mini << " " << maxi << endl;
  }
  return 0;
}