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

const int NUM_MAX = 50000;

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

int getPrimeOverMin(int value){
	if((value & 0x00000001) == 0x00000000){
		++value;
	}else{
		value += 2;
	}
	for(int i=value; i>0; i+=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}

int getPrimeUnderMax(int value){
	if((value & 0x00000001) == 0x00000000){
		--value;
	}else{
		if(value==3)return 2;
		value -= 2;
	}

	for(int i=value; i>2; i-=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}


//0044
int main(){
	int n;
	
	while(cin >> n){
		cout << getPrimeUnderMax(n) << " " << getPrimeOverMin(n) << endl;
	}
	return 0;	
}

C++: #include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

int main(void){

	vector< bool > isP( 60000, true );
	isP[0] = false;
	isP[1] = false;
	for( int i = 2; i < 60000; i++ ) {
		if( !isP[i] ) continue;
		for( int j = 2 * i; j < 60000; j+=i ) {
			isP[j] = false;
		}
	}

	int n;
	while( scanf("%d", &n) != EOF ) {
		int min, max;
		for( int i = n + 1;;i++ ) {
			if( isP[i] ) {
				max = i;
				break;
			}
		}
		for( int i = n - 1;; i-- ) {
			if( isP[i] ) {
				min = i;
				break;
			}
		}
		cout << min << " " << max << endl;
	}

    return 0;
}

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

int main(void){
  int n,prime[MAX+1];

  for(int i = 0 ; i <= MAX ; i++) prime[i] = 1;
  prime[0] = prime[1] = 0;
  for(int i = 2 ; i*i <= MAX ; i++){
    if(prime[i] = 1){
      for(int j = 2*i ; j <= MAX ; j += i){
        prime[j] = 0;
      }
    }
  }

  while(cin >> n){

    for(int k = n - 1 ; k > 0 ; k--){
      if(prime[k] == 1){
        cout << k << ' ';
        break;
      }
    }
   
    for(int l = n + 1 ; l <= MAX ; l++){
      if(prime[l] == 1){
        cout << l << endl;
        break;
      }
    }
  }

  return 0;
}

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;
	while(cin>>n){
		for(int i=n-1;i>=1;--i){
			if(isPrime(i)){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=n+1;;++i){
			if(isPrime(i)){
				cout<<i<<endl;
				break;
			}
		}
	}
}

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

int a[100000];

void sosuu() {
	a[0] = 2;
	int k, z = 1;
	for (int i = 3; i<100000; i++) {
		k = 0;
		for (int j = 0; a[j] <= sqrt(i); j++) {
			if (i%a[j] == 0) {
				k++;
				break;
			}
		}
		if (k == 0) {
			a[z] = i;
			z++;
		}
	}
	return;
}

int nibun(int n, int s, int e){
	if (s >= e) return s;
	if(a[(s + e)/2] < n){
		if(a[(s+e)/2 + 1]>n ){
			return (s + e) / 2;
		}
		return nibun(n, (s + e) / 2 + 1, e);
	}
	else if(a[(s + e) / 2] > n){
		return nibun(n, s, (s + e) / 2 - 1);
	}
	else return (s + e) / 2;
}


int main(){
	sosuu();
	int n, k;
	while(cin >> n){
		int ret = nibun(n, 0, 10000);
		if(n == a[ret]){
			cout << a[ret - 1] << " " << a[ret + 1] << endl;
		}

		else cout << a[ret] << " " << a[ret + 1] << endl;
	}
	return 0;
}

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

int primemax(int m);
int primemin(int m);

int main() {
	int n;
	while (cin << n) {
		cout << primemax(n - 1) << " " << primemin(n + 1) << endl;
	}
}

int primemax(int m) {
	int result = 0;
		while (true) {
		for (int i = m; ; i--) {
			for (int j = sqrt(i)+1;; j--) {
				if ((i%j)==0)break;
				if (j == 2) { result = i; return result; }
			}
		}
	}
}


int primemin(int m) {
	int result = 0;
		while (1) {
			for (int i = m; ; i++) {
				for (int j = sqrt(i)+1; ; j--) {
					if ((i%j)==0)break;
					if (j == 2) { result = i; return result; }
				}
			}
		}
}

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

int prime[51000];

int main(){
	int n;
	
	for(int i = 2; i * i < 51000; ++i){
		if(!prime[i]){
			for(int j = i * i; j < 51000; j += i){
				prime[j] = 1;
			}
		}
	}
	
	while(cin >> n){
		for(int i = n - 1;; --i){
			if(!prime[i]){
				cout << i << ' ';
				break;
			}
		}
		for(int i = n + 1;; ++i){
			if(!prime[i]){
				cout << i << endl;
				break;
			}
		}
	}
}

C++: #include<iostream>
#include<vector>
#define NUM 100000
using namespace std;
int main(){
  int n, prime[NUM], x1,x2;
  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;
      }
  }
  
  while(cin >> n){
    if(n < 3 || n > 50000) continue;
    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<cstdio>
#include<algorithm>

using namespace std;

bool S[60000]={true};

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

int main()
{
	int n;
	set();
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=n-1;true;i--)
		{
			if(S[i])
			{
				printf("%d ",i);
				break;
			}
		}
		for(int i=n+1;true;i++)
		{
			if(S[i])
			{
				printf("%d\n",i);
				break;
			}
		}
	}
}

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

int main(){
  bool is_prime[100000];

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

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

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

    if(cin.eof())
      break;

    for(int i=n-1; i>=2; i--){
      if(is_prime[i]){
	cout << i << ' ';
	break;
      }
    }
    for(int i=n+1; i<=50000; i++){
      if(is_prime[i]){
	cout << i << endl;
	break;
      }
    }
  }

  return 0;
}