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++: #define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
#ifndef FAST_IO
 #define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);
#endif

#define FILE_IO freopen("input.txt","r",stdin)
#define int long long
#define f first
#define s second
#define endl '\n'
#define all(c) c.begin(),c.end()
#define bp __builtin_popcount
#define debug(x) cerr << #x << " = " << x << endl;

const int MOD = 1e9 + 7;
const int INF = 1e18;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template <typename T>void print(T t){for(auto &it : t)cout<<it<<" ";}
inline int powerexp(int a, int b, int m = MOD){ int res = 1;while(b){if(b&1)res = res * a % m;a = a * a % m,b >>= 1;}return res % m;}
inline int modinv(int a){ return powerexp(a,MOD-2,MOD);}
inline int lcm(int a, int b){ int g = __gcd(a,b);return a/g*b;}
inline int add(int x, int y){ x += y; if (x >= MOD) x -=  MOD; return x;}
inline int mul(int x, int y){ return (x * 1ll * y) % MOD;}
inline int sub(int x, int y){ x -= y; if (x<0) x += MOD; return x ;}

//-------------------< start here >-------------------------// 
const int N = 1e5 + 11;
bool isprime[N];
int n;
vector<int> primes;

void solve(){
   	fill(isprime + 2, isprime + N, true);
   	for(int i = 2; i < N; i++){
	  if (isprime[i]){
		primes.push_back(i);
		for(int j = 2; i * j < N; j++){
		  isprime[i * j] = false;	
		}  
	  }	
   }
  while(cin >> n){
	  for(int i = n - 1; ; i--) if (isprime[i]) {cout << i << " "; break;}
	  for(int i = n + 1; ; i++) if (isprime[i]) {cout << i << endl; break;}  
	}
}

//-----------------------------
//comment from here for TOPCODER 
int32_t main(){
   IOS;
   solve();
   //find();
   #ifdef LOCAL_DEFINE
   cerr << "time elapsed " << (double)clock()/CLOCKS_PER_SEC << endl;
   #endif
}

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

int main(){
  bool a[1000000];

  a[0]=a[1]=false;
  for(int i=2;i<1000000;i++){
    a[i]=true;
  }

  for(int i=2;i*i<1000000;i++){
    if(a[i]){
      for(int j=i*i;j<1000000;j+=i){
        a[j]=false;
      }
    }
  }

  int min,max;

  while(true){
    int m;
    cin>>m;

    if(cin.eof()){
      break;
    }

    for(int i=3;i<=m;i++){
      if(a[i]){
        max=i;
      }
    }
    for(int i=m+1;i<=50000;i++){
      if(a[i]){
        min=i;
        break;
      }
    }

    cout<<max<<' '<<min<<endl;

  }

  return 0;
}

C++: #include <bits/stdc++.h>

#define MAX 50022
#define NIL -1

int primes[MAX];

bool isPrime(int n)
{
    if (n <= 1) {
        primes[n] = 0;
        return false;
    }
    if (n <= 3) {
        primes[n] = 1;
        return true;
    }
    if (n % 2 == 0 || n % 3 == 0) {
        primes[n] = 0;
        return false;
    }
    for (int i = 5; i * i <= n; i = i + 6)
        if (n % i == 0 || n % (i + 2) == 0) {
            primes[n] = 0;
            return false;
    }
    primes[n] = 1;
    return true;
}

int main()
{
    for (int i = 1; i <= MAX; i++) primes[i] = NIL;
    int N;
    while(std::scanf("%d", &N) != EOF) {
        int i =1;
        while (1) {
            if (primes[N-i] != NIL) {
                if (primes[N-i] == 1) {
                    std::printf("%d ", N-i);
                    break;
                }
            } else {
                if (isPrime(N-i)) {
                    std::printf("%d ", N-i);
                    break;
                }
            }
            i++;
            if (N-1 == 0) break;
        }
        i = 1;
        while (1) {
            if (primes[N+i] != NIL) {
                if (primes[N+i] == 1) {
                    std::printf("%d\n", N-i);
                    break;
                }
            } else {
                if (isPrime(N+i)) {
                    std::printf("%d\n", N+i);
                    break;
                }
            }
            i++;
            if (N+1 == MAX) break;
        }

    }
    return 0;
}

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

using namespace std;

bool isPrime[60000];

int main(void){
  fill(isPrime, isPrime+60000, true);
  for(int i=2;i<60000;i++){
    if(isPrime[i]){
      for(int j=2; i*j<60000;j++){
	isPrime[i*j] = false;
      }
    }
  }

  int n;
  while(cin >> n){
    int tmp=1;
    int mini=0, maxi = 0;
    while(1){
      if(mini == 0 && isPrime[n-tmp] == true) mini = n-tmp;
      if(maxi == 0 && isPrime[n+tmp] == true) maxi = n+tmp;
      if(mini != 0 && maxi != 0) break;
      tmp++;
    }
    cout << mini << " " << maxi << endl;
  }
  return 0;
}

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


#define N 1000000

bool is_prime(int n){
  if(n <= 1)
    return false;

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

int main(){
    int n;

    bool is_prime[N];
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<N;i++){
      is_prime[i] = true;
    }
    for(int i=2; i*i<N; i++){
      if(is_prime[i]){
        for(int j=i*i;j<N; j+=i){
          is_prime[j] = false;
        }
      }
    }

    while(1){
      int counter = 0;
      cin >> n;
      if(n % 2 == 1){
        cout << 0 << endl;
      } else if(n == 0){
        break;
      } else {
        int i=0;
        while(i <= n/2){
          if(is_prime[n-i] && is_prime[n])
            counter++;
          i++;
        }
        cout << counter << endl;
      }
    }

}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(void){
  int i,no,input;
  int prime[10000];
  int ptr=0,c=0;
  int flag=0;
  int last;
  
  while(cin>>input){
    flag=ptr=c=0;
    prime[ptr++]=2;
    prime[ptr++]=3;
    for(no=5;;no+=2){
      if(flag==2){break;}
      if(input+1<=no){flag=1;c++;}
      if(c==1){if(input==prime[ptr-1])last =ptr-2;else last=ptr-1;}
      for(i=1;i<ptr;i++){
	if(no%prime[i]==0)break;
      }
      if(ptr==i){
	prime[ptr++]=no;
	if(flag==1){flag=2;}
      }
    }
    
    printf("%d %d\n",prime[last],prime[ptr-1]);
  }
    return 0;
}

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

bool ifnprime[100000];

void set(){
    ifnprime[0] = ifnprime[1] = 1;
    for(int n = 2; n * n < 100000; n++){
        if( !ifnprime[n] ){
            int j = n*n;
            while( j < 100000 ){
                ifnprime[j] = 1;
                j += n;
            }
        }
    }
}

int main(){
    int m;
    set();
    while( cin >> m ){
        for(int i = m-1; i >= 0; i-- ){
            if( !ifnprime[i] ){
                cout << i << ' ';
                break;
            }
        }
        for(int i = m+1; i < 100000; i++){
            if( !ifnprime[i] ){
                cout << i << endl;
                break;
            }
        }
    }
    return 0;
}