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>

#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i]<<((i==a.size()-1)?"\n":" ");}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

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

void solve()
{
  vector<int> a;
  FOR(i,2,50100) if(prime(i)) a.push_back(i);
  int n;
  while(~scanf("%d",&n))
  {
    int l = *(lower_bound(a.begin(),a.end(),n)-1);
    int r = *(upper_bound(a.begin(),a.end(),n));
    printf("%d %d\n",l,r);
  }
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

C++: #include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <map>

using namespace std;

#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)

typedef vector<int> vi;

int main()
{
	vi isprime(100000, 1);
	isprime[0] = isprime[1] = 0;
	reep(i, 2, 500){
		if(isprime[i]){
			for(int j=i*2; j<100000; j+=i)
				isprime[j] = 0;
		}
	}

	vi prime;
	rep(i, isprime.size())
		if(isprime[i])
			prime.push_back(i);

	int n;
	while(scanf("%d", &n) != EOF){
		vi::iterator itr = lower_bound(prime.begin(), prime.end(), n);
		printf("%d %d\n", *(itr-1), *(itr+binary_search(prime.begin(), prime.end(), n)));
	}

	return 0;
}

C++: #include <iostream>

using namespace std;

int prime(int n)
{
	if(n < 2){
		return 0;
	} else if(n == 2){
		return 1;
	}
	
	if(n % 2 == 0){
		return 0;
	}
	
	for(int i = 3; i*i <= n; i+= 2){
		if(n % i == 0){
			return 0;
		}
	}
	
	return 1;
}

int main(int argc, char **argv)
{
	int n, s, t;
	
	while(cin >> n){
		for(int i = n-1; i > 2; i--){
			if(prime(i) == 1){
				s = i;
				break;
			}
		}
		for(int i = n+1; i <= 50000; i++){
			if(prime(i) == 1){
				t = i;
				break;
			}
		}
		
		cout << s << " " << t << endl;
	}
	
	return 0;
}

C++: 
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
#define loop(i,b,a) for(int i = b ; i < a; i ++)
const int MAX = 50000;
bool p[MAX];
void isPrime(){
  fill(p,p + MAX,true);
  p[0] = p[1] = false;
  rep(i,MAX){
    if(p[i]){
      for(int j = i + i ; j < MAX ; j += i)
	p[j] = false;
    }
  }
} 

int main(void){
  isPrime();
  int n;
  while(cin>>n){

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

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

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int num;
	vector<int> primeList;
	bool used[50001];
	memset(used, true, sizeof(used));

	for(int i = 2; i < 1000; i++)
	{
		if(used[i] == false)
		{
			continue;
		}
		for(int j = i*2; j < 50001; j += i)
		{
			used[j] = false;
		}
	}
	for(int i = 2; i < 50001; i++)
	{
		if(used[i] == true)
		{
			primeList.push_back(i);
		}
	}
	
	while(cin >> num)
	{
		if(binary_search(primeList.begin(), primeList.end(), num))
		{
			printf("%d %d\n",*(upper_bound(primeList.begin(), primeList.end(), num)-2), *upper_bound(primeList.begin(), primeList.end(), num));
		}
		else
		{
			printf("%d %d\n",*(upper_bound(primeList.begin(), primeList.end(), num)-1), *upper_bound(primeList.begin(), primeList.end(), num));
		}	
	}
}

C++: #include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){

  vector<int>prime;
  bool flag[100000];
  memset(flag,true,sizeof(flag));
  for(int i=2;i<100000;i++)
    {
      if(flag[i])
	{
	  prime.push_back(i);
	  for(int j=i+i;j<100000;j+=i)
	    flag[j]=false;
	}
    }

  int n;
  for(;cin>>n;)
    {
      vector<int>::iterator it1=lower_bound(prime.begin(),prime.end(),n);
      it1--;
      vector<int>::iterator it2=upper_bound(prime.begin(),prime.end(),n);
      cout<<*(it1)<<" "<<*(it2)<<endl;
    }

}

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

int main(){
  bool  prime[100000];
  for(int i=0;i<100000;i++){
    prime[i]=true;
  }
  prime[0]=prime[1]=false;
  for(int i=2;i<1000;i++){
    for(int j=i*2;j*i<100000;j+=i){
      prime[j]=false;
    }
  }
  int n;
  int cnt1=-1,cnt2=-1;
  while(cin>>n){
    for(int i=0;i<n;i++){
      if(prime[i])cnt1=i;
    }
    for(int i=n+1;;i++){
      if(prime[i]){
	cnt2=i;
	break;
      }
    }
    cout<<cnt1<<" "<<cnt2<<endl;
  }
  return 0;
}