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<stdio.h>
int table[55000];
 
int main(){
    for(int i=2;i<1000;i++){
        if(table[i]==0){
            for(int j=i*2;j<=55000;j+=i){
                table[j]=1;
            }
        }
    }
    int a;
    while(~scanf("%d",&a)){
        int i;
        for(i=a-1;table[i]==1;i--);
        printf("%d ",i);
        for(i=a+1;table[i]==1;i++);
        printf("%d\n",i);
    }
}

C++: #include<iostream>
#include<cmath>

using namespace std;

int isPrime[1000000];

int main()
{
	int a;
	
	while(cin >> a){
	
		isPrime[0] = 1;
		isPrime[1] = 1;
		isPrime[2] = 1;
		
		isPrime[a] = -1;
		
		for(int i = 2; i < 50000; i++){
			if(isPrime[i] == 0){
				for(int j = i*2; j < 50000; j+=i){
					isPrime[j] = 1;
				}
			}
		}
		
		/*
		int cont = 0;
		
		for(int i = 0; i < a; i++){
			if(isPrime[i] == 0){
			//	cout << i << endl;
				cont++;
			}
		}
		*/
		
		for(int i = a; i > 0; i--){
			if(isPrime[i] == 0){
				cout << i << " " << flush;
				break;
			}
		}
		for(int i = a; i < 50000; i++){
			if(isPrime[i] == 0){
				cout << i <<endl;
				break;
			}
		}
	}
}

C++: #include<cstdio>


int main(){
	int n, t;
	int f[50101] = {};

	for(int i = 2; i < 25051; i++){
		f[i * 2] = 1;
	}

	for(int i = 3; i <= 224; i += 2){
		for(int j = 3; j * i <= 50100; j += 2){
			f[i * j] = 1;
		}		
	}

	while(scanf("%d", &n) + 1){
		t = n - 1;
		while(f[t]){
			t--;
		}
		printf("%d ", t);
		t = n + 1;
		while(f[t]){
			t++;
		}
		printf("%d\n", t);
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> sosu(60000, 1);

void eratos() {
  for(int i = 2; i < 30000; i++) {
    sosu[2*i] = 0;
  }
  for(int i = 3; i*i < 60000; i+=1) {
    if(sosu[i] == 1) {
      for(int j = 1; i*j < 60000; j++) {
	sosu[i*(j+2)] = 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 < 60000; i++) {
      if(sosu[i] == 1) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;

int main(void){
  int prime[50002],i,j,x;

  for(i=0;i<50001;i++)
    prime[i]=0;
  prime[0]=1;
  prime[1]=1;

  
  for(i=2;i*i<50001;i++){
    if(prime[i]==0){
      for(j=i*2;j<50001;j+=i){
	prime[j]=1;
      }
    }
  }

  while(scanf("%d",&x)!=EOF){
    for(i=x-1;i>=2;i--){
      if(prime[i]==0){
	cout << i <<" ";
	break;
      }
    }
    
    for(i=x+1;i<50001;i++){
      if(prime[i]==0){
	cout << i << endl;
	break;
      } 
    }
  }
  return 0;
}

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

int main(){
	
	int n;
	int s[60000]={0};
	
	s[2]=0;
	
	for(int i=3;i<=60000;i+=2){
		int k=0;
		for(int j=3;j<=sqrt(i);j+=2){
			if(i%j==0)
			{
				k=1;
				break;
			}
		}
		if(k==0)
			s[i]=1;
	}
	while(cin>>n){
		for(int i=n-1;i>=2;i--){
		if(s[i]==1){
			cout<<i<<" ";
			
			break;
		}
	}
	for(int i=n+1;i<=60000;i++){
		if(s[i]==1){
			cout<<i<<endl;
			break;
		}
	}
	
	}
}

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

int main(){
	const int size = 60000;
	bool prime[size + 1];
	int n;
	
	for(int i = 0; i <= size; i++) prime[i] = false;
	for(int i = 2; i <= size; i++){
		if(!prime[i]){
			for(int j = 2 * i; j <= size; j += i){
				prime[j] = true;
			}
		}
	}
	
	while((scanf("%d", &n)) != EOF){
		for(int i = n - 1; i >= 0; i--){
			if(!prime[i]){
				printf("%d ", i);
				break;
			}
		}
		for(int i = n + 1; i <= size; i++){
			if(!prime[i]){
				printf("%d\n", i);
				break;
			}
		}
	}
	
	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }



int n;

const int MAX = 100000;
bool IsPrime[MAX];
vector<int> Era(int n = MAX) {
    vector<int> res;
	IsPrime[0] = false; IsPrime[1] = false; 
	for (int i = 2; i < n; ++i) IsPrime[i] = true;
	for (int i = 2; i < n; ++i) {
		if (IsPrime[i]) {
            res.push_back(i);
			for (int j = i*2; j < n; j += i) IsPrime[j] = false;
		}
	}
    return res;
}


int main() {
    vint prime = Era();
    while (cin >> n) {
        int it = lower_bound( ALL(prime), n ) - prime.begin();
        if ( prime[it] == n ) {
            cout << prime[it-1] << " " << prime[it+1] << endl;
        }
        else {
            cout << prime[it-1] << " " << prime[it] << endl;
        }
    }
    
    return 0;
}

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

bool is_prime(int n){
  if(n<=1)
    return false;

  for(int i=2; i*i<=n; i++){
    if(n%i==0){
      return false;
    }
  }

  return true;
}


int main(){
  while(true){
    int next=0;
    int prev=0;

    int n;
    cin >> n;

    if(cin.eof())
      break;

    for(int i=n+1; i<=50100; i++){
      if(is_prime(i)){
        next=i;
        break;
      }
    }
    for(int i=n-1; i>=2; i--){
      if(is_prime(i)){
        prev=i;
        break;
      }
    }

    cout << prev << ' ' << next <<endl;
  }

  return 0;
}

C++: #include <iostream>
#include <vector>

#define MAX_N 50000

using namespace std;

bool isprime(int n) {
	for (int i = 2; i * i <= n; i++)
		if (n % i == 0)
			return false;
	return n != 1;
}

int main() {
	int n;
	int g, l;
	vector<int> prime;
	for (int i = 2; i < MAX_N * 2; i++)
		if (isprime(i) == true)
			prime.push_back(i);
	while (cin >> n) {
		g = l;
		vector<int>::iterator it = prime.begin();
		while (it != prime.end()) {
			if (*it < n)
				g = *it;
			if (*it > n) {
				l = *it;
				break;
			}
			it++;
		}
		cout << g << " " << l << endl;
	}
	return 0;
}