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 <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 q = upper_bound(Pv.begin(), Pv.end(), n) - Pv.begin();
    int p = q-1;
    if(Pv[p] == n) --p;
    cout << Pv[p] << " " << Pv[q] << endl;
  }
  return 0;
}

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

int main() {
	ios_base::sync_with_stdio( false );

	const int N = 50021;
	vector<bool> primes( N+1, true );

	primes[0] = false;
	primes[1] = false;

	for( int i = 2; i*i <= N; ++i ) {
		if( primes[i] ) {
			for( int j = 2*i; j <= N; j += i ) {
				if( j%i == 0 ) {
					primes[j] = false;
				}
			}
		}
	}

	int x;
	while( cin >> x ) {
		int i = x-1;
		int j = x+1;
		while( i >= 0 && !primes[i] ) { i -= 1; }
		while( j <= N && !primes[j] ) { j += 1; }

		cout << i << ' ' << j << '\n';
	}

	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[50001];
int main()
{
  for(int i = 2;i <50001;i++){
    prime[i] = true;
  }
  prime[0] = false;
  prime[1] = false;
  for(int j = 2;j <50001;j++){
    if(prime[j]){
      for(int i =2*j;i <50001;i+=j){
	prime[i] = false;
      }
    }
  }
  int x;
  
  while(cin>>x){
    int min_ans = 0;
    int max_ans = 0;
    for(int i = x-1;i >1;i--){
      if(prime[i]){
	min_ans = i;
	break;
      }
    }
    for(int i = x+1;i <50001;i++){
      if(prime[i]){
	max_ans = i;
	break;
      }
    }
    cout <<min_ans<<" "<<max_ans<<endl;
  }
  return 0;
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

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

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


bool prime[50010];
vector <int> pri;

int main(){
	memset(prime,0,sizeof(prime));
	rep(i,50010){
		prime[i]=true;
	}
	prime[1]=false;
	prime[0]=false;
	for(int i=1;i*i<50010;i++){
		if(prime[i]){
			//cout<<i<<" ";
			for(int j=i*i;j<50010;j+=i){
				prime[j]=false;
			}
		}
	}
	rep(i,50010){
		if(prime[i]) pri.push_back(i);
	}
	
	int n;
	while(cin>>n){
		int smo,lar;
		rep(i,50010){
			if(pri[i]<n){
			}
			else{
				if(prime[n]==true){
					smo=pri[i-1];
					lar=pri[i+1];
				}
				else{
					smo=pri[i-1];
					lar=pri[i];
				}
				break;
			}
		}
		cout<<smo<<" "<<lar<<endl;
	}
	
	return 0;
}

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

#define MAX_N 50010

int prime[MAX_N];
bool is_prime[MAX_N + 1];


void prime_generate(){
	int p = 0;
	for(int i = 0; i <= MAX_N; i++) is_prime[i] = true;

	is_prime[0] = is_prime[1] = false;

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

void solve(int n){
	for(int i = 0; i < MAX_N; i++){
		if(prime[i] == n){
			cout << prime[i-1] << " " << prime[i+1] << endl;;
			break;
		}
		else if(prime[i] > n){
			cout << prime[i-1] << " " << prime[i] << endl;
			break;
		}
		else continue;
	}
}

int main(){
	prime_generate();

	int n;
	while(cin >> n){
		solve(n);
	}
}

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(int k = n - 1 ; prime[k] == 0 ; k--);
    cout << k << ' ';

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

  return 0;
}

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

int prime[MAX+1];

void is_prime(void){

  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){

    for(int k = n - 1 ; k > 0 ; k--){
      if(prime[k] == 1){
        cout << k << ' ';
        break;
      }
    }
   
    for(int l = n + 1 ; l < MAX ; l++){
      if(prime[l] == 1){
        cout << l << endl;
        break;
      }
    }
  }

  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>

using namespace std;

bool is_prime(int p) {
    for (int i=2; i*i<=p; i++) {
        if (p % i == 0) return false;
    }
    return true;
}

int main() {
    int N;
    while (cin >> N) {
        for (int p1=N-1; ; p1--) {
            if (is_prime(p1)) break;
        }
        for (int p2=N+1; ; p2++) {
            if (is_prime(p2)) break;
        }
        cout << p1 << " " << p2 << endl;
    }
    return 0;
}

C++: #include <iostream>

using namespace std;

int main(){
        bool list[50001];
        for(int i = 2; i*i <= 50000; i++){
                for(int j = 2; !list[i] && i*j <= 50000; j++){
                        list[i*j] = true;
                }   
        }   
        int n;
        while(cin >> n){ 
                int min = n;
                while(list[--min]);
                int max = n;
                while(list[++max]);
                cout << min << " " << max << endl;
        }   
}

C++: #include <iostream>
using namespace std;
bool t[60000] = {false};
int main()
{
	int n, c, i, j, a, b;
	t[0] = true;
	for (i = 2; i * i <= 60000; i++)
	{
		if (!t[i-1])
		{
			for (j = i+i; j <= 60000; j+=i)
				t[j-1] = true;
		}
	}
	while (cin >> n)
	{
		if (cin.eof()) break;
		for (i = n-1; i >= 2; i--)
			if (!t[i-1])
			{
				a = i;
				break;
			}
		for (i = n+1; i < 60000; i++)
			if (!t[i-1])
			{
				b = i;
				break;
			}
		cout << a << " " << b << endl;
	}
}