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<cstdio>
#include<cstdlib>
#include<vector>
using namespace std;
int main()
{ 
  const int END = -1;
  const int NUM = 50000;
  int num;
  int i,index,index2;
  
  cin >> num;

  vector<int> eratos(NUM);

  for(i = 0;i < NUM - 1 ; i++)
    eratos[i] = i+2;
  eratos[i] = END;
 
  while(!cin.eof()){
    i = 0;
    index2 = 0;
  while(eratos[i]!=END)
    {
      if(eratos[i]!=0)
        {
          index = i + 1;
          while(eratos[index]!=END)
            {    
              if(eratos[index]%eratos[i] == 0)
                {
                  eratos[index] = 0;
                }
              index++;
            }
          
          eratos[index2] = eratos[i];
          
          index2++;
        }

      if(eratos[index2-1] > num)
          break;
      i++;
    }
  if(eratos[index2-2] == num)
    cout << eratos[index2-3] << " " << eratos[index2-1] << endl;
  else
    cout << eratos[index2-2] << " " << eratos[index2-1] << endl;

    cin >> num;

  }
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

int main(){
	
	int n;
	int s[60000]={0};
	
	s[2]=1;
	
	for(int i=3;i<=60000;i+=2){
		int k=0;
		for(int j=3;j<=sqrt(i);j+=2){
			if(i%j==0)
			{
				k=1;
				break;
			}
		}
		if(k==0)
			s[i]=1;
	}
	while(cin>>n){
		for(int i=n-1;i>=2;i--){
		if(s[i]==1){
			cout<<i<<" ";
			
			break;
		}
	}
	for(int i=n+1;i<=60000;i++){
		if(s[i]==1){
			cout<<i<<endl;
			break;
		}
	}
	
	}
}

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


int prime[60000];


void sieve(){
	memset(prime, 1, sizeof prime);
	int i;
	for(i = 2;i*i <= 60000;i++){
		if(prime[i]){
			for(int j = 2;i*j <= 60000;j++){
				prime[i*j] = 0;
			}
		}
	}
}


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

C++: #include<iostream>
#include<vector>
#define NUM 100000
using namespace std;
int main(){
  int n, prime[NUM],flag;
  vector<int> p;
  for(int i=0; i<NUM; i++) prime[i] = 0;
  prime[0] = 1;
  for(int i=2; i<=NUM/2; i++){
      for(int j=2; i*j <= NUM; j++){
	if(prime[i*j-1] == 0)
	  prime[i*j-1] = 1;
      }
  }
  
  for(int i=0; i<NUM; i++){
    if(prime[i] == 0)
      p.push_back(i+1);
  }

  while(cin >> n){
    flag=0;
    if(n < 3 || n > 50000) return 0;
    vector<int>::iterator it = p.begin();
    while(it != p.end()){
      if(n == *it){
	cout << *(it-1) << " " << *(it+1) << endl;
	flag=1;
      }
      it++;
    }
    if(flag == 0) return 0;
  }
  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 <cstring>
using namespace std;
int main(){
	int n,m;
	bool f[50001];
	memset(f,true,sizeof(f));
	for(int i=2;i<50001;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				f[i]=false;
				break;
			}
		}
	}
	while(cin>>n){
		for(int i=n-1;;i--){
			if(f[i]){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=n+1;;i++){
			if(f[i]){
				cout<<i;
				break;
			}
		}
		cout<<endl;
	}
	return 0;
}

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

const int MAX_S = 100000;
bool p[MAX_S];


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

int main() {
  int x;
  prime();
  while(cin >> x) {
    int n = 2;
    bool b = false;
    for(int i = 3; i < MAX_S; i++) {
      if(b && n > x) {
        cout << n << endl;
        break;
      }

      if(i == x) {
        cout << n << ' ';
        b = true;
      }

      if(p[i]) n = i;
    }
  }
}

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


#define N 50000

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<1000; 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 == 0)
        break;
      if(cin.eof())
        break;
      int i=0;
      while(i <= n/2){
        if(is_prime[n-i] && is_prime[n])
          counter++;
        i++;
        }
        cout << counter << endl;
      }
      return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#include<bitset>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    int it = 0, i = 0;
    bitset<51000> eratos;
    vector<int> prime;
    prime.push_back(2);

    range(j,2,51000)
        eratos[j] = 1;
    eratos[0] = 0;
    eratos[1] = 0;

    while(i < 51000){
        while(1){
            if(eratos[i] == 1){
                prime.push_back(i + 1);
                break;
            }
            i++;
        }
        for(int j = 2; prime[it] * j - 1 < 51000; j++){
            int num = prime[it] * j - 1;
            eratos[num] = 0;
        }
        it++; i++;
    }

    int input;
    while(cin >> input){
        rep(i, 5500){
            if(input < prime[i]){
                if(input > prime[i - 1])
                    cout << prime[i - 1];
                else
                    cout << prime[i - 2];
                cout << ' ' << prime[i];
                break;
            }
        }
    }
}

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

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

int main(){
  int n;
  while(cin>>n){
    for(int i=n-1;i>1;i--){
      if(xp(i)){
	cout<<i<<" ";break;
      }
    }
    for(int i=n+1;;i++){
      if(xp(i)){
	cout<<i<<endl;break;
      }
    }
  }
  return 0;
}