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<cmath>
using namespace std;
int x[1000000];
int main() {
	for (int i = 2; i < 1000000; i++) {
		for (int j = 2; j <= sqrt(i); j++) {
			if (i%j == 0) {
				goto E;
			}
		}
		x[i] = 1;
	E:;
	}
	int a, b;
	while (cin >> a >> b) {
		for (int i = a - 1; i >= 0; i--) {
			if (x[i] == 1) { cout << i << ' '; break; }
		}
		for (int i = a + 1; i < 1000000; i++) {
			if (x[i] == 1) { cout << i << endl; break; }
		}
	}
}

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

const int MAXP = 70004;

bool isP[MAXP];
vector<int> Pv;

int init() {
  fill(isP, isP+MAXP, true);
  isP[0] = isP[1] = false;
  for(int i = 2; i < MAXP; ++i) {
    if(!isP[i]) continue;
    Pv.push_back(i);
    for(int j = i*2; j < MAXP; j += i) isP[j] = false;
  }
  return Pv.size();
}

int main() {
  int n;
  init();
  while(cin >> n) {
    int p = lower_bound(Pv.begin(), Pv.end(), n) - Pv.begin();
    int q = p+1;
    if(Pv[p] == n) --p;
    cout << Pv[p] << " " << Pv[q] << endl;
  }
  return 0;
}

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

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

int main() {
  eratos();

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

    if(n%2==0) n = n-1; 
    
    for(int i = n-1; i >= 0; i-=2) {
      if(sosu[i] == 1) {
	cout << i << endl;
	break;
      }
    }
    for(int i = n+1; i < 50000; i+=2) {
      if(sosu[i] == 1) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

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

using namespace std;

int main(){
    
    vector<int> vec;
    bool sosu[50050]={false};
    
    vec.push_back(2);
    for(int i=3;i<50050;i+=2){
        if(sosu[i]) continue;
        vec.push_back(i);
        for(int j=i+i;j<50050;j+=i){
            sosu[j] = true;
        }
    }
   
    int n;
    while(cin >> n){
        cout << *(lower_bound(vec.begin(),vec.end(),n)-1) << " " << *upper_bound(vec.begin(),vec.end(),n) << endl;
    }
   
    return(0);
}

C++: #include<iostream>
#include<vector>
#define m 60000
using namespace std;
 int main(){
    int n,cnt=0;
    vector<bool>a(m+1,true);
    for(int i=2;i*i<=m;i++)
         if(a[i]) for(int j=i+i;j<=m;j+=i)  a[j]=false;   
    int p[50000];  
    for(int i=2;i<=m;i++){
            if(a[i]) { p[cnt]=i;cnt++; }
    }

    while(1){
        cin>>n;
        if(cin.eof()) break;
        for(int i=0;i<cnt;i++){
            if(p[i]<n && p[i+1]>n) {
		cout<<p[i]<<" "<<p[i+1]<<endl;
            }else if(p[i]==n) {
                cout<<p[i-1]<<" "<<p[i+1]<<endl;}
       } 
    }
    return 0;
}

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 ++)
#define loop(i,b,a) for(int i = b ; i < a; i ++)
const int MAX = (1e8);
bool p[MAX];
short num[MAX];
void isPrime(){
  rep(i,MAX)p[i] = true;
  p[0] = p[1] = false;
  num[0] = num[1] = 0;
  loop(i,2,MAX){
    num[i] = num[i-1] + p[i];
    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 = n-1;
  while(!p[i--]);
  cout<<++i<<' ';
  i = n + 1;
  while(!p[i++]);
  cout<<--i<<endl;
  }
  return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 50000;
int n;
int prime[MAX_N];
bool isPrime[MAX_N+1];
int ptr;
int pos;

int main()
{
  prime[ptr++] = 2;
  for(int i=2; i<=MAX_N; i+=2) isPrime[i] = true;
  for(int i=3; i<=MAX_N; i+=2){
    if(!isPrime[i]){
      prime[ptr++] = i;
      for(int j=2*i; j<=MAX_N; j+=i){
        isPrime[j] = true;
      }
    }
  }

  while((cin >> n) && n){
    pos = upper_bound(prime, prime+ptr, n) - prime;
    cout << (prime[pos-1]==n ? prime[pos-2] : prime[pos-1]) << " " << prime[pos] << endl;
  }

  return 0;
}

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

const int MAX = 100000;

int main ()
{
    vector<int> num(MAX + 1, 1);
    num[0] = num[1] = -1;
    for (int i = 2; i <= MAX / 2; i++) {
        for (int j = 2; i * j <= MAX; j++) {
            num[i*j] = -1;
        }
    }

    vector<int> prim;
    for (int i = 0; i < num.size(); i++) {
        if (num[i] == 1) {
            prim.push_back(i);
        }
        num[i] = prim.size() - 1;
    }

    int n;
    while (cin >> n) {
        if (prim[num[n]] == n)
            cout << prim[num[n]-1] << " " << prim[num[n]+1] << endl;
        else
            cout << prim[num[n]] << " " << prim[num[n]+1] << endl;
    }

    return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
bool prime[51010];
int main()
{
  for(int i = 2;i <51011;i++){
    prime[i] = true;
  }
  prime[0] = false;
  prime[1] = false;
  for(int j = 2;j*j <51011;j++){
    if(prime[j]){
      for(int i =2*j;i <51011;i+=j){
	prime[i] = false;
      }
    }
  }
  int x;
  
  while(cin>>x){
 
    for(int i = x-1;i >1;i--){
      if(prime[i]){
	cout << i;
	break;
      }
    }
    bool flag = false;
    for(int i = x+1;i <51011;i++){
      if(prime[i]){
	cout <<" "<<i <<endl;
	flag = true;
	break;
      }
    }
    if(!flag){
      cout <<endl;
    }

  }
  return 0;
}