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 <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <sstream>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <numeric>
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <fstream>
using namespace std;

bool isprime (int n){

	if (n == 0 || n == 1){
		return false;
	}else if (n == 2){
		return true;
	}else if (n % 2 == 0){
		return false;
	} // end if
	
	for (int i = 3; i <= sqrt(n); i+= 2){
		if (n % i == 0){
			return false;
		} // end if
	} // end for
		
	return true;
}

int main()
{
//	cut here before submit 
//	freopen("testcase.p2", "r", stdin);
	string str = "";

	while (getline (cin, str ) ){
		if (str.empty() ){
			break;
		} // end if
		int n;
		stringstream ss(str);
		ss >> n;
		int i;
		int res1 = 0;
		int res2 = 0;

		for (i = n + 1;; ++i){
			if (isprime(i) ){
				res1 = i;
				break;
			} // end if
		} // end for
	
		for (i = n - 1;; --i){			
			if (isprime(i) ){
				res2 = i;
				break;
			} // end if
		} // end for

		cout << res2 << ' ' << res1 << endl;
	} // end for
		
	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 prime[51000];

int main(){
	int n;
	
	for(int i = 2; i * i < 51000; ++i){
		if(!prime[i]){
			for(int j = i * i; j < 51000; j += i){
				prime[j] = 1;
			}
		}
	}
	
	while(cin >> n){
		for(int i = n - 1;i > 2; --i){
			if(!prime[i]){
				cout << i << ' ';
				break;
			}
		}
		for(int i = n + 1; i < 51000; ++i){
			if(!prime[i]){
				cout << i << endl;
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <math.h>
using namespace std;

int main() {
	
	int n,w;
	
	while(cin>>n){
		for(int i=n-1;i>1;i--){
			w=0;
			for(int j=2;j<224;j++){
				if(i%j==0&&i/j!=1)w=1;
			}
			if(w==0){cout<<i<<" ";break;}
		}
		for(int i=n+1;;i++){
			w=0;
			for(int j=2;j<224;j++){
				if(i%j==0&&i/j!=1)w=1;
			}
			if(w==0){cout<<i<<endl;break;}
		}
	}
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

int main(void){
  int prime[50000];
  int prime_f[51001];
  int k;
  int n;
  int i,j;
  int n_size;

  while(cin>>n){
    k=0;
    memset(prime_f,0,sizeof(prime_f));
    prime_f[0]=prime_f[1]=1;
    for(i=2;i<51000;i++){
      if(!prime_f[i]){
	k++;
	prime[k]=i;
	for(j=2*i;j<51000;j+=i){
	  prime_f[j]=1;
	}
      }
    }

    for(i=0;i<k;i++){
      if(prime[i]>=n){
	if(prime[i]==n){
	  cout<<prime[i-1]<<" "<<prime[i+1]<<endl;
	}else{
	  cout<<prime[i-1]<<" "<<prime[i]<<endl;
	}
	break;
      }  
    }
  }
  return(0);
}

C++: #include<iostream>
#include<vector>
#define NUM 100000
using namespace std;
int main(){
  int n, prime[NUM];
  vector<int> p;
  for(int i=0; i<NUM; i++) prime[i] = 0;
  prime[0] = 1;
  for(int i=2; i<=NUM/2; i++){
      for(int j=2; i*j <= NUM; j++){
	if(prime[i*j-1] == 0)
	  prime[i*j-1] = 1;
      }
  }
  
  for(int i=0; i<NUM; i++){
    if(prime[i] == 0)
      p.push_back(i+1);
  }

  while(cin >> n){
    if(n < 3 || n > 50000) return 0;
    vector<int>::iterator it = p.begin();
    while(it != p.end()){
      if(n == *it)
	cout << *(it-1) << " " << *(it+1) << endl;
      it++;
    }
  }
  return 0;
  
}

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

int main(){
  int table[55000]={};
  for(int i=2; i*i<55000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=55000; j+=i){
        table[j]=1;
      }
    }
  }
  int n;
  while(cin >> n,n){
    int i;
    for(i=n-1; table[i]; --i);
    cout << i << " ";
    for(i=n+1; table[i]; ++i);
    cout << i << endl;
  }
  return 0;
}

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

#define MAX 1000000

vector<int> prime;
bool is_prime[MAX+1];

void Sieve() {
  
  for(int i=0; i<=MAX; i++) {
    is_prime[i] = true;
  }
  
  is_prime[0] = is_prime[1] = false;
  
  for(int i=2; i<=MAX; i++) {
    if(is_prime[i]) {
      prime.push_back( i );
      for(int j=2*i; j<=MAX; j+=i) is_prime[j] = false;
    }
  }
}

int main() {
  
  Sieve();
  
  int n;
  while(cin >> n) {
    int temp = n;
    while(n--) {
      if( is_prime[n] ) {
	cout << n << " ";
	break;
      }
    }

    while(temp++) {
      if( is_prime[temp] ) {
	cout << temp << endl;
	break;
      }
    }
  }
  
  return 0;
}

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

#define MAX 100000 

bool prime_table[MAX];
int head;

int main(){
	int n, i, j;
	int last;
	// make table
	for (i = 0; i < MAX; i++) {
		if(i==0||i==1){
			prime_table[i] = false;
		}else{
			prime_table[i] = true;
		}
	}
	// find prime
	for (i = 2; i < MAX; i++) {
		if(prime_table[i]){
			for (j = i+i; j < MAX; j+=i) {
				prime_table[j] = false;
			}
		}
	}
	
	while(cin >> n){
		for (i = 0; i <= MAX; i++) {
			if(prime_table[i]){
				if(i > n){
					cout << last << " " << i << endl;
					break;
				}else if(i != n){
					last = i;
				}
			}
		}
	}
	return 0;
}

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

const int SIZE = 50100;

int main(int argc, char *argv[]) {
	// make sieve
	vector<bool> sieve(SIZE, true);
	vector<int> prime;
	for (int i = 2; i < SIZE; i++) {
		if (sieve[i]) {
			prime.push_back(i);
			//printf("%d\n", i);
			for (int j = i+i; j < SIZE; j+=i) {
				sieve[j] = false;
			}
		}
	}
	sort(prime.begin(), prime.end());
	// load data
	int rcv;
	const int prime_size = static_cast<int>(prime.size());
	while (EOF != fscanf(stdin, "%d", &rcv)) {
		for (int i = 0; i < prime_size; i++) {
			if (prime[i] > rcv) {
				if (prime[i-1] != rcv)
					printf("%d %d\n", prime[i-1], prime[i]);
				else
					printf("%d %d\n", prime[i-2], prime[i]);
				break;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
#define MAX 100000
 
int main()
{
    vector<int> p;
    bool prime[MAX];
    fill(prime, prime + MAX, 1);
    prime[0] = prime[1] = 0;
    for (int i = 2; i < MAX; i++) {
        if (prime[i]) {
            p.push_back(i);
            for (int j = 2*i; j < MAX; j += i) {
                prime[j] = 0;
            }
        }
    }
 
    int N;
    while (cin >> N) {
        cout << *(lower_bound(p.begin(), p.end(), N) - 1) << " " <<
                *upper_bound(p.begin(), p.end(), N) << endl;
    }
    return 0;
}