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;

const int MAX_S = 550000;
bool p[MAX_S];


void prime() {
  fill(p, p+MAX_S, true);
  p[0] = p[1] = false;
  for(int i = 2; i < MAX_S; i++) {
    if(p[i]) {
      for(int j = 2; i*j < MAX_S; j++) {
        p[i*j] = false;
      }
    }
  }
}

int main() {
  int x;
  prime();
  while(cin >> x) {
    int n;
    bool b = false;
    for(int i = 3; i < MAX_S; i++) {
      if(b && x != n) {
        cout << n << endl;
        break;
      }
      if(x == i) {
        cout << n << ' ';
        b = true;
      }
      if(p[i]) n = i;
    }
  }
}

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


int main(){
	bool prime[60000];
	for(int i=0;i<60000;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<60000;i++){
		if(prime[i]==1){
			for(int j=i*2;j<60000;j+=i){
				prime[j]=0;
			}
		}
	}
	int n;
	while(cin>>n){
		int i;
		for(i=1;prime[n-i]==0;i++);
		cout<<n-i<<" ";
		for(i=1;prime[n+i]==0;i++);
		cout<<n+i<<endl;
	}
}

C++: #include <cstdio>
#include <cstring>
const int MAX = 100000;
bool isPrime[MAX];

int main(void) {
  
  for(int i = 0 ; i < MAX ; i++)
    isPrime[i] = true;
  
  isPrime[0] = isPrime[1] = false;
  
  for(int i = 0 ; i < MAX ; i++)
    if(isPrime[i] == true)
      for(int j = i + i ; j < MAX ; j += i)
	isPrime[j] = false;
  
  int input;
  while(scanf("%d", &input) != EOF) {
    for(int i = input - 1 ; i > 0 ; i--)
      if(isPrime[i] == true) { printf("%d ", i); break; }
    
    for(int i = input + 1 ; i < MAX ; i++)
      if(isPrime[i] == true){ printf("%d\n", i); break; }
  } 
  return 0;
}

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

int main() {
    int n;
    vector<int> prime;
    vector<bool> is_prime(100000, true);
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<is_prime.size(); ++i) {
        if(is_prime[i]) {
            prime.push_back(i);
            for(int j=i+i; j<is_prime.size(); j+=i) {
                is_prime[j] = false;
            }
        }
    }
    while(cin >> n) {
        auto it = lower_bound(prime.begin(), prime.end(), n);
        auto it2 = upper_bound(prime.begin(), prime.end(), n);
        cout << *(it-1) << ' ' << *it2 << endl;
    }
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>

inline bool isp(int n) {
    int ed = (int) sqrtf((float) n);
    for (int i = 2; i <= ed; ++i) {
        if (!(n % i)) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;

    while (scanf("%d", &n) != EOF) {
        int mx = 0;
        int mi = 0;

        for (int i = n - 1; 1 < i; --i) {
            if (isp(i)) {
                mx = i;
                break;
            }
        }

        for (int i = n + 1; i < 50000; ++i) {
            if (isp(i)) {
                mi = i;
                break;
            }
        }

        printf("%d %d\n", mx, mi);
    }

    return 0;
}

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

bool prime[MAX];
void calcPrime(){
	for(int i = 2; i < MAX; i++) prime[i] = true;
	for(int i = 2; i < MAX; i++){
		if( prime[i] ){
			for(int j = i+i; j <= MAX; j += i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	int n;
	calcPrime();
	while( cin >> n ){
		int under = -1, over = -1;
		for(int d = n-1, u = n+1; ; d--, u++){
			if( under != -1 && over != -1 ) break;
			if( prime[d] ) under = d;
			if( prime[u] ) over = u;
		}
		cout << under << " " << over << endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <cassert>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <bitset>
#include <sstream>
#include <istream>
#include <cmath>
#include <cstdio>

using namespace std;

#define vci vector<int>
#define vcs vector<string>
#define pb push_back
#define sz size()
#define mapii map<int, int>
#define mapci map<char, int>
#define mapsi map<string, int>
#define all(x) x.begin(), x.end()
#define minit(a, i) memset(a, i, sizeof(a));

#define for_(i, a, b) for (int i=(int)a; i<(int)b; i++)
#define for_d(i, a, b) for (int i=(int)a-1; i>=b; i--)
#define for_r(i, a, b, c) for (int i=(int)a; i<(int)b; i += c)
#define for_dr(i, a, b, c) for (int i=(int)a-1; i>=b; i -= c)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

typedef long long ll;

const int iINF = 2147483647;
const ll lINF = 9223372036854775807;

template <class T> inline void dbg(T t) { cout << t << endl; }




vector<int> n_prime(int n) {
	vector<int> ret;
	vector<bool> is_prime(n + 1, 1);
	for (int i = 2; i <= n; i++) {
		if (is_prime[i]) {
			ret.push_back(i);
			for (int j = i + i; j <= n; j += i) is_prime[j] = 0;
		}
	}
	return ret;
}

int main() {
	vci primes = n_prime(50000 * 2);
	int n;
	
	while (cin >> n) {		
		vci::iterator it = upper_bound(all(primes), n), it_ = it;
		it_--;
		if ((*it_)==n) it_--;
		cout << (*it_) << " " << (*it) << endl;
	}
	
	return 0;
}

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;
      }
    }
  }
 
  while(true){
    int n;
    cin >> n;
 
    if(cin.eof())
        break;
 
    int high = n;
    int low = n;
 
    while(1){
      high = high+1;
      if(is_prime[high]){
        break;
      }
    }
 
    while(1){
      low = low-1;
      if(is_prime[low]){
        break;
      }
    }
 
    cout << low << " " << high << endl;
  }
 
  return 0;
}

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

#define MAX_N 51000

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);
	}
}