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 <cstdio>
using namespace std;

#define MAX 50022

int main(void)
{
	bool p[MAX];
	vector <int> prime;
	int i, j;
	
	for (i = 0; i < MAX; i++){
		p[i] = true;
		if (i % 2 == 0) p[i] = false;
	}
	prime.push_back(2);
	for (i = 3; i < MAX; i += 2){
		if (p[i]){
			prime.push_back(i);
			for (j = 1; i * j < MAX; j++){
				p[i * j] = false;
			}
		}
	}
	/*
	for (i = 0; i < prime.size(); i++){
		printf("%d ", prime[i]);
	}*/
	
	int n;
	while (cin >> n){
		if (n == EOF) return 0;
		int a, b;
		for (i = 0; i < prime.size(); i++){
			if (prime[i] < n) a = prime[i];
			if (n < prime[i]) {
				b = prime[i];
				break;
			}
		}
		printf("%d %d\n", a, b);
	}
	
	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<vector>
#include<queue>
#include<list>
#include<stack>
#include<algorithm>
#include<cmath>
#include<memory>
#include<array>

using namespace std;

int main()
{
  array<int, 50030> pn{};

  for ( auto i = 2; i < pn.size(); ++i )
    {
      if ( pn[i] == 0 )
        {
          for ( auto j = 2 * i; j < pn.size(); j += i )
            {
              pn[j] = 1;
            }
        }
    }

  int n;

  while ( cin >> n )
    {
      int i;
      for ( i = 1; pn[n - i] == 1; ++i );
      cout << n - i << " ";
      for ( i = 1; pn[n + i] == 1; ++i );
      cout << n + i << endl;
    }
  
  return 0;
}

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

using namespace std;

int main() {
    vector<int> primes;
    vector<int> is_prime(60001, 1);
    is_prime[0] = is_prime[1] = 0;
    int lim = (int)sqrt(60000);
    for(int i = 2; i <= lim; ++i) {
        if(is_prime[i]) {
            if(i < lim) {
                for(int j = i*i; j <= 60000; j += i) is_prime[j] = 0;
            }
        }
    }
    for(int i = 2; i <= 60000; ++i) 
        if(is_prime[i]) primes.push_back(i);

    int n;
    while(cin >> n) {
        cout << *(lower_bound(primes.begin(), primes.end(), n)-1) << ' ' << *upper_bound(primes.begin(), primes.end(), n) << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
#define int long long
signed main(){
	vector<int> primes(50050,1);
	for(int i=2;i<230;i++){
		if(primes[i]==0) continue;
		for(int j=i+1;j<50050;j++){
			if(j%i==0) primes[j] = 0;
		}
	}
	int a;
	int prev = -1;
	while( scanf("%lld", &a) != EOF ){
		for(int i=0;i<50050;i++){
			if(i<a && primes[i]==1) prev = i;
			if(a<i && primes[i]==1 ){ cout << prev << " " << i << endl; break;}
		}
	}
	return 0;
}

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

using namespace std;
bool isPrime(int num);

int main(){
	int n;
	while(cin >> n, n){
		int prev = 0;
		int next = 0;
		for(int i = 2; (n-i) >= 3 && (n+i) <= 50000; i += 2){
			if(isPrime(n-i) && prev == 0)
				prev = n-i;
			if(isPrime(n+i) && next == 0)
				next = n+i;
		}
		cout << prev << " " << next << endl;
	}
	return 0;
}

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

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

const int MAXN = 60000;

bool prime[MAXN] = {true, true};

int main()
{
  for (int i = 2; i * i < MAXN; i++){
    for (int j = i * i; j < MAXN; j += i){
      prime[j] = true;
    }
  }

  int n;
  
  while (~scanf("%d", &n)){
    for (int i = n - 1; i >= 2; i--){
      if (!prime[i]){
        printf("%d ", i);
        break;
      }
    }
    for (int i = n + 1; i < MAXN; i++){
      if (!prime[i]){
        printf("%d\n", i);
        break;
      }
    }
  }

  return (0);
}

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

int main(){
  int table[80000]={};
  for(int i=2; i*i<80000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=80000; 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 <bits/stdc++.h>
using namespace std;

vector<int> primes;
bool is_prime[100010];

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

int main() {
	calc_prime(100000);
	int n;
	while(cin >> n){
		auto it = lower_bound(primes.begin(), primes.end(), n);
		cout << *(it - 1) << " ";
		if(*it == n)
			cout << *(it + 1) << endl;
		else
			cout << *it << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<vector>
#define m 50000
using namespace std;
 int main(){
    int n,cnt=0;
    vector<bool>a(m+1,true);
    for(int i=2;i*i<=m;i++)
         if(a[i]) for(int j=i+i;j<=m;j+=i)  a[j]=false;   
    int p[50000];  
    for(int i=2;i<=m;i++){
            if(a[i]) { p[cnt]=i;cnt++; }
    }

    while(1){
        cin>>n;
        if(cin.eof()) break;
        for(int i=0;i<cnt;i++){
            if(p[i]<n && p[i+1]>n) {
		cout<<p[i]<<" "<<p[i+1]<<endl;
            }else if(p[i]==n) {
                cout<<p[i-1]<<" "<<p[i+1]<<endl;}
       } 
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#define N 51000
using namespace std;

int main(){

	int pn[N], n, p;

	fill(pn, pn+N, 1);
	for(int i=2; i<N; i++){
		if(pn[i] == 1){
			for(int j=2; (p = i * j)<N; j++){
				pn[p] = 0;
			}
		}
	}
	
	while(cin >> n){
		for(int i=n-1; i>0; i--){
			if(pn[i] == 1){
				cout << i << " ";
				break;
			}
		}
		for(int i=n+1; i<=50000; i++){
			if(pn[i] == 1){
				cout << i << endl;
				break;
			}
		}		
	}

	return 0;

}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007

vector<ll> Eratosthenes(ll n,vector<ll>& arr){

	for(ll i = 0; i < n;i++){
		arr[i] = 1;
	}
	for(ll i = 2; i < sqrt(n); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) < n; j++){
				arr[i *(j + 2)] = 0;
			}
		}
    }
    return arr;
}


int main(){


    ll n;
    
    while(cin >> n){
        ll m = n * 10;
        ll ans_mini = INF,ans_maxi = INF;
        vector<ll> arr(m);
        arr = Eratosthenes(m,arr);        
        REP(i,arr.size()){
            if(i < n && arr[i]){
                ans_mini = i;
            }
            if(i > n && arr[i]){
                ans_maxi = i;
                break;
            }
        }
        cout << ans_mini << " " << ans_maxi << endl;
    }
    
    return 0;
}