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 <vector>
#include <cmath>
#include <cstring>
using namespace std;

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#define __typeof__ decltype
#endif

#define ITER(c) __typeof__((c).begin())
#define FOREACH(it, c) for (ITER(c) it = (c).begin(); it != (c).end(); ++it)

const int limit = 50050;

void prime_list(vector<unsigned int> &plist, unsigned int max_prime){

    if(plist.size() && plist[plist.size()-1] >= max_prime ) return;
    if(max_prime <= 2){
        plist.push_back(2);
        return;
    }

    unsigned int rt = int(sqrt((double)max_prime));
    prime_list(plist, rt);

    unsigned int bias = plist[plist.size()-1] + 1;
    if(bias == 3) bias = 2;
    unsigned int num = (max_prime - bias + 1) / 2;
    if(num == 0) return;

    char *l = new char[num];
    memset(l, 1, num);

    FOREACH(it, plist){
        unsigned int prime = *it;
        if(prime > rt) break;
        unsigned int st = max(rt - (rt % prime), prime);
        for(unsigned int i = st; i <= max_prime; i += prime){
            if(i >= bias){
                unsigned int idx = i - bias;
                if(idx % 2 == 1){
                    l[idx/2] = 0;
                }
            }
        }
    }
    for(unsigned int i = 0; i < num; i++){
        if(l[i]){
            plist.push_back(bias + 1 + i * 2);
        }
    }
    delete l;
    return;
}

int main(){
    vector<unsigned int> q;
    prime_list(q, limit);

    unsigned int n;
    while(std::cin >> n){
        int l = 0, r = q.size()-1, c = -1;
        while(l <= r){
            c = (l + r)/2;
            if(q[c] < n){ l = c + 1; continue; }
            if(q[c] > n){ r = c - 1; continue; }
            break;
        }
        if(l > r) c = r;
        if(q[c] == n){
            cout << q[c-1] << " " << q[c+1] << endl;
        } else {
            cout << q[c] << " " << q[c+1] << endl;
        }
    }
}

C++: #include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main(){

	int data[50010+1];
	int state=0;
	//素数表の作成
	for(int i=1;i<=50010;i++){
		data[i]=0;
		state = 0;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				state=1;
				break;
			}
		}
		if(state==0){
			data[i]=1;
		}
	}
	int num;

	while(cin>>num){
		int ans0,ans1;

		for(ans0=num-1;;ans0--){
			if(data[ans0]==1){
				break;
			}
		}
		for(ans1 = num+1;;ans1++){
			if(data[ans1]==1){
				break;
			}
		}
		cout<<ans0<<" "<<ans1<<endl;
	}
	return 0;

}

/*
Sample Input
19
3517
Output for the Sample Input
17 23
3511 3527
*/

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

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

int main() {
	int n;
	while (cin << n) {
		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;
#define NUM 100000
int main( void )
{
	vector <bool> is_prime( NUM+1, false );
	is_prime[2] = true;
	for ( int i = 3; i < NUM; i += 2 )
	{
		is_prime[i] = true;
	}
	for ( int i = 3; i < NUM; i += 2 )
	{
		if ( is_prime[i] )
		{
			for ( int j = i+i; j < NUM; j += i )
			{
				is_prime[j] = false;
			}
		}
	}

	int n;
	while ( cin >> n )
	{
		for ( int i = n-1; i >= 2; i-- )
		{
			if ( is_prime[i] )
			{
				cout << i << " ";
				break;
			}
		}

		for ( int i = n+1; i <= NUM; i++ )
		{
			if ( is_prime[i] )
			{
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  vector<bool> prime(1e5, true);
  prime[0] = prime[1] = false;
  for(int i = 2; i * i < 1e5; ++i) {
    if(prime[i]) {
      for(int j = i * i; j < 1e5; j += i) {
        prime[j] = false;
      }
    }
  }
 
  int n;
  while(cin >> n, !cin.eof()) {
    for(int i = n - 1;; --i) {
      if(prime[i]) {
        cout << i << " ";
        break;
      }
    }
    for(int i = n + 1;; ++i) {
      if(prime[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}

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

int main(){
	bool dt[51001];
	dt[0]=false;dt[1]=false;dt[2]=true;
	int count=0;
	for(int i=3;i<51001;i++){
		for(int j=2;j<i && j<5000;j++){
			if(dt[j]==true){if(i%j==0)count++;}
		}
		if(count==0){dt[i]=true;}else{dt[i]=false;}
		count=0;
	}
	int n=0;
	while(cin>>n){
		int i=0;
		int ansf=0,ansl=0;
		for(i=1;i<n;i++){
			if(dt[i]==true){ansf=i;}
		}
		i++;
		while(i>0){
			if(dt[i]==true){ansl=i;i=-10;}
			i++;
		}
		cout<<ansf<<" "<<ansl<<endl;
	}
	return 0;
}

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

int main()
{
	int n;
	while(cin>>n){
		int na, nb;
		bool flag = true;
		for(int i=n-1;i>1;i--){
			for(int j=2;j*j<i;j++){
				if(i % j == 0){
				flag = false;
				break;
				}
			}
			if(flag){
			na = i;
			break;
			}
			flag = true;
		}
		
		flag = true;
		for(int i=n+1;;i++){
			for(int j=2;j*j<i;j++){
				if(i % j==0){
					flag = false;
					break;
				}
			}
			if(flag){
				nb = i;
				break;
			}
			flag = true;
		}
		
		cout<<na<<' '<<nb<<endl;
	}
	return 0;
}

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

using namespace std;

bool isPrime[55000];
vector<int> prime;

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

void solve()
{
	primeCalc();
	int n;
	while(cin >> n)
	{
		int pos = 0;
		while(true)
		{
			if(prime[pos] >= n)
			{
				cout << prime[pos - 1] << " ";
				break;
			}
			++pos;
		}
		if(prime[pos] == n)
		{
			cout << prime[pos + 1] << endl;
		}
		else
		{
			cout << prime[pos] << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

void eratos() {
  for(int i = 2; i < 30000; i++) {
    sosu[2*i] = 0;
  }
  for(int i = 3; i < 20000; i+=2) {
    sosu[3*i] = 0;
  }
  for(int i = 5; i < sqrt(60000); i+=2) {
    if(sosu[i] == 1) {
      for(int j = 1; i*(j+2) < 60000; j++) {
	sosu[i*(j+2)] = 0;
      }
    }
  }
}

int main() {
  eratos();

  while(1) {
    int n;
    cin >> n; 
    
    for(int i = n-1; i >= 0; i--) {
      if(sosu[i] == 1) {
	cout << i << ' ';
	break;
      }
    }
    for(int i = n+1; i < 60000; i++) {
      if(sosu[i] == 1) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}