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 <vector>
#include <cmath>
using namespace std;
vector<int> sosu(70000, 1);

void eratos() {
  for(int i = 2; i*i < 70000; i++) {
    if(sosu[i] == 1) {
      for(int j = 2; i*j < 70000; j++) {
	sosu[i*j] = 0;
      }
    }
  }
}

int main() {
  eratos();

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

C++: #include<iostream>
#include<cmath>
#include<vector>
int main()
{
	std::vector<bool>is_prime(50020, true);
	const int root = static_cast<int>(floor(sqrt(50021)));
	for (int i = 0; i <= root - 2; i++)
	{
		if (is_prime[i])
		{
			for (int j = i + 2; (i + 2) * j < 50021; j++)
			{
				is_prime[(i + 2) * j - 2] = false;
			}
		}
	}
	for (int n; std::cin >> n;)
	{
		for (int i = n - 2 - 1;; i--)
		{
			if (is_prime[i])
			{
				std::cout << i + 2 << ' ';
				break;
			}
		}
		for (int i = n - 2 + 1;; i++)
		{
			if (is_prime[i])
			{
				std::cout << i + 2 << std::endl;
				break;
			}
		}
	}
	return 0;
}

C++: // 2011/07/12 Tazoe

#include <iostream>
using namespace std;

void eratos(bool is_prime[], int n)
{
	if(n>=1)
		is_prime[0] = false;
	if(n>=2)
		is_prime[1] = false;

	for(int i=2; i<n; i++)
		is_prime[i] = true;

	for(int i=2; i<n; i++){
		if(!is_prime[i])
			continue;
		for(int j=i+i; j<n; j+=i)
			is_prime[j] = false;
	}
}

int main()
{
	bool is_prime[60000];
	eratos(is_prime, 60000);

	while(true){
		int n;
		cin >> n;
		if(cin.eof())
			break;

		int pre;
		for(pre=n-1; !is_prime[pre]; pre--);

		int pos;
		for(pos=n+1; !is_prime[pos]; pos++);

		cout << pre << ' ' << pos << endl;
	}

	return 0;
}

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

int prime[MAX];

void is_prime(){
  for(int i = 0 ; i < MAX ; i++) prime[i] = 1;
  
  prime[0] = prime[1] = 0;
  for(int i = 2 ; i*i < MAX ; i++){
    if(prime[i] = 1){
      for(int j = 2*i ; j < MAX ; j += i){
        prime[j] = 0;
      }
    }
  }
}

int main(void){
  int n;

  is_prime();

  while(cin >> n){
    int k,l;
    for(k = n - 1 ; prime[k] == 0 ; k--);
    cout << k << ' ';

    for(l = n + 1 ; prime[l] == 0 ; l++);
    cout << l << endl;
  }

  return 0;
}

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

int smallprime(int x)
{
	for(int i=x; i<2; i--)
	{
		if((i%2==0) ||(i%3==0) || (i%4==0)||(i%5==0)||(i%6==0) || (i%7==0) || (i%8==0) || (i%9==0))
			continue;
		else
		{
			if((i/1==i) && (i/i==1))
				return i;
			break;
		}
	}
}
	int bigprime(int x)
	{
		for(int i=x; ; i++)
		{
			if((i%2==0) ||(i%3==0) || (i%4==0)||(i%5==0)||(i%6==0) || (i%7==0) || (i%8==0) || (i%9==0))
			continue;
		else
		{
			if((i/1==i) && (i/i==1))
				return i;
			break;
		}
		}
	}
	int main()
	{
		int x;
		while(cin>>x)
		{
			if((x<3) || (x>50000))
				break;
			else
			{
				cout<<smallprime(x)<<" "<<bigprime(x)<<endl;
			}
		}
		return 0;
	}

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

bool prime[50001];
int main(){
  memset( prime ,true ,sizeof(prime) );
  prime[0] = prime[1] = false;
  for( int i=2 ; i*i<=50000 ; i++ ){
    if( prime[i] == true ){
      for( int j=i+i ; j<=50000 ; j+=i ){
	prime[j] = false;
      }
    }
  }

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

  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=j+i){
        is_prime[j] = false;
      }
    }
  }

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

    int a,b;
    int cnt=0;
    for(int i=3;i<=n;i++){
      if(is_prime[i]){
        a=i;
        for(int j=3;j<=n;j++){
          if(is_prime[j]){
            b=j;
            if(a+b==n){
              cnt++;
            }
          }
        }
      }
    }
    if(n==0)
        break;

    cout << cnt/2+1 << endl;
  }

  return 0;
}

C++: #include <cstdio>

using namespace std;

int prime(int n){
	for(int i=2;i<=n/2;i++){
		if((n%i)==0)return 0;
	}
	return 1;
}
int main()
{
	int n;
	while(~scanf("%d\n",&n)){
		for(int i=n-1;0<=i;i--){
			if(prime(i)==1){
				printf("%d ",i);
				break;
			}
		}
		for(int i=n+1; ;i++){
			if(prime(i)==1){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool p[50001];

void prime() {
  fill(p, p+50001, true);
  p[0] = false;
  p[1] = false;

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

int main() {
  int n, min, max;
  prime();

  while(cin >> n) {
    max = 2;
    for(int i = 3; i < n; i++) {
      if(p[i] && max < i) max = i;
    }
    for(int i = n+1; i < 50001; i++) {
      if(p[i]) {
	min = i;
	break;
      }
    }
    cout << max << ' ' << min << endl;
  }
}