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<cmath>
#define NUM 100000
using namespace std;
int main(){
  int n, prime[NUM+1], x1,x2;
  prime[1]=0;
  for(int i=2; i<NUM+1; i++) prime[i] = 1;
  for(int i=2; i<=NUM/2; i++){
      for(int j=2; i*j <= NUM; j++){
      	  prime[i*j]=0;
      }
  }

  while(cin >> n){
    if(n < 3 || n > 50000) return 0;
    for(int i=1; i<NUM; i++){
      if(prime[n-i-1] == 1){
      	  x1 = n-i-1;
      	  break;
      }
    }
    for(int i=1; i<NUM; i++){
      if(prime[n+i-1] == 1){
      	  x2 = n+i-1;
      	  break;
      }
  	}
  	
  	cout << x1 << " " << x2 << endl;

  }
  return 0;
  
}

C++: #include <stdio.h>

int isprime(int x){
  if(!(x&1)) return 0;
  
  int i;
  for(i=3;i*i<x;i+=2){
    if(!(x%i)) return 0;
  }
  return 1;
}

int main(){
  int n;
  while(scanf("%d", &n)!=EOF){
    int i;

    int bottom=0;
    for(i=n-1;i>=2;i--) if(isprime(i)) bottom = i,i=0;

    int upper=0;
    for(i=n+1;i<=60000;i++) if(isprime(i)) upper=i,i=70000;

    printf("%d %d\n", bottom, upper);
  }
}

C++: #include <iostream>
using namespace std;
 
int main(){
  bool is_prime[51000];
 
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<51000;i++){
    is_prime[i] = true;
  }
 
  for(int i=2;i*i<51000;i++){
    if(is_prime[i]){
      for(int j=i*i;j<51000;j=j+i){
        is_prime[j] = false;
      }
    }
  }
 
  while(true){
    int n;
    cin >> n;
 
    if(cin.eof())
        break;
 
    int high = n;
    int low = n;
 
    while(1){
      high = high+1;
      if(is_prime[high]){
        break;
      }
    }
 
    while(1){
      low = low-1;
      if(is_prime[low]){
        break;
      }
    }
 
    cout << low << " " << high << endl;
  }
 
  return 0;
}

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

const int MAX_S = 550000;
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;
    bool b = false;
    for(int i = 2; i < MAX_S; i++) {
      if(b && x != n) {
        cout << n << endl;
        break;
      }
      if(x == i) {
        cout << n << ' ';
        b = true;
      }
      if(p[i]) n = i;
    }
  }
}

C++: require 'prime'
while str=gets
    s=str.to_i
    low = -((1-s)..(-3)).find{|i| (i).prime? }
    high = ((s+1)..50000).find{|i| i.prime? }
    puts "#{low} #{high}"
end

C++: #include<iostream>
using namespace std;
bool isPrime(int n){
	if(n<2)return false;
	for(int i=2;i*i<=n;++i){
		if(n%i==0){
			return false;
		}
	}
	return true;
}
main(){
	int n;
	cin>>n;
	for(int i=n-1;i>=1;--i){
		if(isPrime(i)){
			cout<<i<<endl;
			break;
		}
	}
	for(int i=n+1;;++i){
		if(isPrime(i)){
			cout<<i<<endl;
			break;
		}
	}
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <string>
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,P> pip;
typedef long long ll;
const int inf=1<<30;
const double pi=acos(-1);

int n;
vi sosu;

int nibu(int s,int t,int x){
	if(t-s==1) return s;
	int k=(s+t)/2;
	if(sosu[k]>x) return nibu(s,k,x);
	else return nibu(k,t,x);
}

int main(){
	vector<bool> used(50105,1);
	for(int i=2;i<50100;i++){
		if(used[i]){
			sosu.push_back(i);
			for(int j=i+i;j<=50100;j+=i) used[j]=0;
		}
	}
	while(cin>>n){
		int tmp=nibu(0,sosu.size(),n);
		if(sosu[tmp]==n) cout<<sosu[tmp-1]<<' '<<sosu[tmp+1]<<endl;
		else cout<<sosu[tmp]<<' '<<sosu[tmp+1]<<endl;
	}
}

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

int main()
{
  bool is_prime[100000];

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

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

  while(1){
    int n;
    cin >> n;

    if(cin.eof())
      break;

    int i, j;
    while(1){
      i = n-1;
      if(is_prime[i])
        break;
      i--;
    }

    while(1){
      j = n+1;
      if(is_prime[j])
        break;
      j++;
    }

    cout << i << ' ' << j << endl;
  }
  return 0;
}

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;
      }
    }

    if(m==2){
      max=2;
    }

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

  }

  return 0;
}

C++: #include<iostream>
int main(){
	int n;
	while(std::cin>>n){
		int a=n,b=n,e,d;
		while(1){
			int count=0;
			a--;
			for(int i=2;i<a/2;i++){
				if(a%i==0)count++;
			}
			if(count==0){
				d=a;
				break;
			}
		}
		while(1){
			int count2=0;
			b++;
			for(int i=2;i<b/2;i++){
				if(b%i==0)count2++;
			}
			if(count2==0){
				e=b;
				break;
			}
		}
		std::cout<<d<<" "<<e<<std::endl;
	}
	return 0;
}