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 <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const int MAX_N = 50030; 

bool prime[MAX_N];
vector<int> p;

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

	p.clear();
	rep (i, MAX_N ){
		if (prime[i] ) p.push_back (i );
	} // end rep

//	cerr << "last_prime: " << p[p.size() - 1] << endl;
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.PNII", "r", stdin );
	make_prime ();

	int n;
	while (~scanf ("%d", &n ) ){
		int max_p, min_p;
		vector<int>::iterator it = upper_bound (ALL (p ), n );
		int i = (int)(it-p.begin());
		min_p = p[i];
		for (; i >= 0; i-- ){
			if (p[i] < n ){
				max_p = p[i];
				break;
			} // end if
		} // end for
		printf ("%d %d\n", max_p, min_p );
	} // end while	

	return 0;
}

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 bool is_prime(int x)
 {
   for(int i=2;i<=(int)sqrt(x);i++)
   {
     if(x%i==0) return false;        
   }     
   return true;
 }
 
 int main()
 {
   int N;
   while(cin>>N)
   {
     int min=N;
     int max=N;
     while(min--) if(is_prime(min)) break;   
     while(max--) if(is_prime(min)) break;
     cout<<min<<" "<<max<<endl;            
   }
   //while(1);
   return 0;
 }

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	vector<bool>v(50010, true);
	v[0] = v[1] = false;
	rep(i, 2, sqrt(50010)) {
		if (v[i]) {
			for (int j = i + i; j < 50010; j += i) {
				v[j] = false;
			}
		}
	}
	int n;
	while (cin >> n) {
		for (int i = n-1;; i--) {
			if (v[i]) {
				cout << i;
				break;
			}
		}
		for (int i = n + 1;; i++) {
			if (v[i]) {
				cout << " " << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

#define MAX_N 50000

using namespace std;

bool isprime(int n) {
	for (int i = 2; i * i <= n; i++)
		if (n % i == 0)
			return false;
	return n != 1;
}

int main() {
	int n;
	int g, l, cur;
	vector<int> prime;
	for (int i = 2; i <= MAX_N; i++)
		if (isprime(i) == true)
			prime.push_back(i);
	while (cin >> n) {
		g = l = cur = 2;
		vector<int>::iterator it = prime.begin();
		while (it != prime.end()) {
			g = cur;
			cur = l;
			l = *it;
			if (l > n)
				break;
			it++;
		}
		cout << g << " " << l << endl;
	}
	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*i < 60000; i+=2) {
    if(sosu[i] == 1) {
      for(int j = 1; i*j < 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;
}

C++: #include<iostream>

using namespace std;
bool flag[50001];
int main()
{
	flag[0]=flag[1]=true;

	for(int i=2;i<50001;i++)
	{
		if(!flag[i])
		{
			for(int j=i*2;j<50001;j+=i) flag[j]=true;
		}
	}

	int n,low,up;
	while(cin>>n)
	{
		for(int i=n-1;;i--)
		{
			if(!flag[i]) {low=i; break;}
		}
		for(int i=n+1;;i++)
		{
			if(!flag[i]) {up=i; break;}
		}
	
		cout<<low<<" "<<up<<endl;
	}
	return 0;
}

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

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

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

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

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

    return 0;
}