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;

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(){
    int n;

    bool is_prime[1000000];
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<1000000;i++){
      is_prime[i] = true;
    }
    for(int i=2; i*i<1000000; i++){
      if(is_prime[i]){
        for(int j=i*i;j<1000000; j+=i){
          is_prime[j] = false;
        }
      }
    }

    int n_prime[1000000];

    int cnt = 0;
    for(int i=0;i<1000000;i++){
      if(is_prime[i]){
        cnt++;
      }
      n_prime[i] = cnt;
    }

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

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

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

}

C++: #include <iostream>
using namespace std;
int p[50100];
int main()
{
  int i,j;
  for(i=2;i*i<50100;i++){
    if(p[i]==0){
      for(j=i*2;j<50100;j+=i){
	p[j] = 1;
      }
    }
  }
  while(cin >> i){
    for(j=i-1;p[j];j--){}
    cout << j << ' ';
    for(j=i+1;p[j];j++){}
    cout << j << endl;
  }
  return 0;
}

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

int P[10010];
map<int,int> idx;

void prime() {
  int i=3,j,k,cnt=1;
  P[0] = 2;
  for(i=3;i<=50100;i+=2){
    k=0;
    for(j=3;j<=sqrt(i);j+=2){
      if(i%j==0){
	k=1;
	break;
      }
    }
    if(k==0) {
      P[cnt] = i;
      cnt++;
    }
  }
  for(int i=0;i<cnt;i++){
    idx[P[i]] = i;
  }
}

int main(){
  int n;
  prime();
  while(cin >> n){
    cout << P[idx[n]-1] << " " << P[idx[n]+1] << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
int main(void){
  int w;
  int n;
  int num=0;
  while(cin>>w,w){
    cout<<"Case "<<++num<<":"<<endl;
    cin>>n;
    vector<pair<int,int> > in(n);
    rep(i,n){
      int a,b;
      scanf("%d,%d",&a,&b);
      in[i]=make_pair(a,b);
   }    
    int resw = 0;
    int resm = 0;
    int last = 1<<n;
    for(int i = 1 ; i < last+1 ; i ++){
      //cout<<i<<endl;
      int nw = 0;
      int money = 0;
      rep(j,n-1){
	bool use = (i/(1<<j))%2;
	if(use){
	  money += in[j].first;
	  nw += in[j].second;
	}
      }
      if(nw>w)continue;
      if(resm<money){
	//rep(k,n-1)cout<<(i/(1<<k))%2<<" ";
	//cout<<endl;
	  
	resm = money;
	resw = nw;
      }
      if(money==resm && resw<nw){
	resw = nw;
      }
      //cout<<i<<" "<<resw<<endl;
      //cout<<endl;
    }
    cout<<resm<<endl<<resw<<endl;

    //*/
  }
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

void Eratosthenes(int n,vi& primes)
{
	primes.assign(n+1,0);
	repi(i,2,n+1)
		primes[i]=1;
	repi(i,2,n+1){
		if(primes[i]==0)
			continue;
		for(int j=i+i;j<=n;j+=i)
			primes[j]=0;
	}
}

int main()
{
	vi isPrimes;
	Eratosthenes(50021,isPrimes);
	vi primes;
	rep(i,isPrimes.size())
		if(isPrimes[i])
			primes.push_back(i);
	
	for(int n;cin>>n;){
		int a=*(lower_bound(allof(primes),n)-1);
		int b=*upper_bound(allof(primes),n);
		cout<<a<<" "<<b<<endl;
	}
	
	return 0;
}

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

int main() {
	int n;
	while (cin >> n) {
		int max_num = 0;
		int new_num = 0;
		for (int i = 1;; i++) {
			int sn = n - i;
			int bn = n + i;
			if (max_num == 0) {
				if (sn <= 3) {
					if (sn == 2 || sn == 3) max_num = sn;
					continue;
				}
				else {
					if (sn % 2 == 0 || sn % 3 == 0) continue;
					if (sn % 6 != 1 && sn % 6 != 5) continue;
					bool check = true;
					for (int j = 5; j * j < sn; j += 6) {
						if (sn % j == 0) check = false;
						if (sn % (j + 2) == 0) check = false;
						if (check == false) break;
					}
					if (check == true) max_num = sn;
				}
			}
			if (new_num == 0) {
				if (bn <= 3) {
					if (bn == 2 || bn == 3) new_num = bn;
					continue;
				}
				else {
					if (bn % 2 == 0 || bn % 3 == 0) continue;
					if (bn % 6 != 1 && bn % 6 != 5) continue;
					bool check = true;
					for (int j = 5; j * j < bn; j += 6) {
						if (bn % j == 0) check = false;
						if (bn % (j + 2) == 0) check = false;
						if (check == false) break;
					}
					if (check == true) new_num = bn;
				}
			}
			if (max_num != 0 && new_num != 0) break;
		}
		cout << max_num << " " << new_num << endl;
	}
	return 0;
}

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

bool p[50050];

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

	for(int i=0; i *i < 50050; i++){
		if(!p[i]) continue;
		for(int j = i + i; j < 50050; j+= i){
			p[j] = false;
		}
	}
}

int input;
int big, small;

int main(){
	erato();
	while(scanf("%d", &input) != EOF){
		big = small = input;
		big++; small--;
		while(1){
			if(p[small] && p[big]) break;
			if(!p[small])small--;
			if(!p[big])big++;
		}
		cout << small << " " << big << endl;
	}
}

C++: 19
3517

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

int main(){
  bool is_prime[50001];

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

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

  int n_prime[50001];

  int cnt = 0;
  for(int i=0;i<50001;i++){
    if(is_prime[i]){
      cnt++;
    }
    n_prime[i] = cnt;
  }

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

    if(cin.eof())
        break;

    int high,low;
    for(int i=0;i<50001;i++){
      if((is_prime[i]) && (n_prime[i] == n_prime[n]-1)){
        low = i;
      }
      if((is_prime[i]) && (n_prime[i] == n_prime[n]+1)){
        high = i;
      }
    }

    cout << low << " " << high << endl;
  }

  return 0;
}