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<stdio.h>
using namespace std;

int primemax(int m);
int primemin(int m);

int main() {
	int n;
	while (scanf("%d",&n) != EOF) {
		cout << primemax(n - 1) << " " << primemin(n + 1) << endl;
	}
}

int primemax(int m) {
	int result = 0;
		while (true) {
		for (int i = m; ; i--) {
			for (int j = sqrt(i)+1;; j--) {
				if ((i%j)==0)break;
				if (j == 2) { result = i; return result; }
			}
		}
	}
}


int primemin(int m) {
	int result = 0;
		while (1) {
			for (int i = m; ; i++) {
				for (int j = sqrt(i)+1; ; j--) {
					if ((i%j)==0)break;
					if (j == 2) { result = i; return result; }
				}
			}
		}
}

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

using namespace std;



int main(){
	int in;
	int prime[50001] = {};

	vector<int> p;
	int i, j;
	for (i = 2; i*i < 50000; i++){
		if (prime[i] == 0){
			for (j = 2; i*j <= 50000; j++){
				prime[i*j] = 1;
			}
		}
	}
	for (i = 1; i < 50001; i++){
		if (prime[i] == 0){
			p.push_back(i);
		}
	}



	while (cin >> in){
		for (i = 1; in >= p[i]; i++);
		if (p[i - 1] == in){
			cout << p[i - 2] << " " << p[i] << endl;
		}
		else{
			cout << p[i - 1] << " " << p[i] << endl;
			break;
		}
	}
}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str();}
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-12;
const double PI = acos(-1.0);
const int INF = INT_MAX/10;

int main() {
	vi prime(1000001, 1);
	prime[0] = prime[1] = 0;
	FOR(i, 2, 1000) {
		if(prime[i]) {
			for(int j = i*2; j <= 1000000; j += i) {
				prime[j] = 0;
			}
		}
	}

	int n;
	while(cin >> n) {
		int minP, maxP;
		REP(i, n) {
			if(prime[i]) {
				minP = i;
			}
		}
		FOR(i, n+1, 100000) {
			if(prime[i]) {
				maxP = i;
				break;
			}
		}

		cout << minP << " " << maxP << 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 = 1000000;
int main(void){
  bool prime[MAX];
  rep(i,MAX)prime[i] = true;
  prime[0] = prime[1] = false;
  loop(i,2,i * i){
    if(prime[i]){
      for(int j = i + i ; j < MAX ; j += i){
	prime[j] = false;
      }
    }
  }
  //rep(i,100)if(prime[i])cout<<i<<endl;
  int n;
  while(cin>>n){
    int mi,ma;
    mi = n-1; 
    ma = ++n;
    while(!prime[mi]){
      mi--;
    }
    while(!prime[ma]){
      ma++;
    }
    
    cout<<mi<<" "<<ma<<endl;
  }
}

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

int main() {

  const int size = 50022;
  int seq[size] = {};

  for (int i = 2; i < size; ++i)
    for (int j = i * 2; j < size; j += i)
      seq[j] = 1;

  int n;
  while (cin >> n) {
    int v1, v2;

    for (int i = n-1; 0 < i; --i) {
      if (seq[i] == 0) {
        v1 = i;
        break;
      }
    }

    for (int i = n+1; 0 < size; ++i) {
      if (seq[i] == 0) {
        v2 = i;
        break;
      }
    }

    cout << v1 << " " << v2 << endl;
  }

  return EXIT_SUCCESS;
}

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) == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;

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

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

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

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

    return 0;
}

C++: #include<iostream>

using namespace std;

const int MAX_NUM = 100000000;
bool prime_number[MAX_NUM];
 
void prime_create() {
  fill(prime_number, prime_number + MAX_NUM, true);
  prime_number[0] = prime_number[1] = false;
 
  for(int i = 2; i < MAX_NUM; i++) {
    if(prime_number[i])
      for(int j = 2; i*j < MAX_NUM; j++) {
	prime_number[i*j] = false;
      }
  }
}

int main(void){
  prime_create();
  int n;
  while(cin>>n){
    int i;

    for(i = (!prime_number[n]?n:n-1) ; !prime_number[i] ; i --);
    cout<<" "<<i<<" ";
    for(i = (!prime_number[n]?n:n+1) ; !prime_number[i] ; i ++);
    cout<<i<<endl;
  }
}

C++: #include<iostream>
using namespace std;
int main(){
  bool num[1000000]={false};
  for(int i=2; i<=1000; i++)
    if(!num[i])
      for(int j=i*i; j<1000000; j+=i)
	num[j] = true;
  int n;
  while(cin >>n){
    for(int i=n-1;;i--){if(!num[i]){cout <<i<<" ";break;}}
    for(int i=n+1;;i++){if(!num[i]){cout <<i<<endl;break;}}

  }
  return 0;
}

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

bool isPrime(int n){
  for(int i=2;i<=sqrt((double)n);i++){
    if(n%i == 0)return false;
  }
  return true;
}


int main(){
  int in;
  while(cin >> in){
    for(int i=in-1;i>=1;i--){
      if(isPrime(i)){
	cout << i << " ";
	break;
      }
    }
    for(int i=in+1;i<=60000;i++){
      if(isPrime(i)){
	cout << i << endl;
	break;
      }
    }

  }
  return 0;
}