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 <cstring>
#define MAX_N 50000
using namespace std;

bool prime[MAX_N + 1];

bool isPrime(int n) {
    //今回、０、１をこの関数の引数に取らない
    for(int r = 2; r * r <= n; r++) {
        if(n % r == 0) return(false);
    }
    return(true);
}

void initialize() {
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = false; //0,1は素数ではない。
    for(int r = 2; r <= MAX_N; r++) {
        if(isPrime(r)) {
            for(int c = r * 2; c <= MAX_N; c += r) prime[c] = false; //倍数は素数で無い事が分かっている
        }
    }
}

int searchSmall(int num) {
    for(int r = num - 1; r >= 0; r--)
        if(isPrime(r)) return(r);
    return(-1);
}

int searchLarge(int num) {
    for(int r = num + 1; r <= MAX_N; r++)
        if(isPrime(r)) return(r);
    return(-1);
}

int main(void) {
    initialize();
    
    int input;
    while(cin >> input) {
        int max = searchLarge(input), min = searchSmall(input);
        cout << min << " " << max << endl;
    }
    return(0);
}

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

using namespace std;

int main(void) {
	int n;

	while (cin >> n) {

		bool f1 = false;

		for (int j = n - 1; j > 1; j--) {
			for (int i = 2; i <= sqrt(j); i++) {
				if ((j % i) == 0) {
					f1 = true;
					break;
				}
			}
			if (!f1) {
				cout << j << " ";
				break;
			}
			f1 = false;
		}

		bool f2 = false;

		for (int j = n + 1; true; j++) {
			for (int i = 2; i <= sqrt(j); i++) {
				if ((j % i) == 0) {
					f2 = true;
					break;
				}
			}
			if (!f2) {
				cout << j << endl;
				break;
			}
			f2 = false;
		}
	}
}

C++: #include <iostream>
#include<string>
#include <math.h>
using namespace std;

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

int main() {
   
    std::string str;
    int num = 0;
    while(std::cin>>num){
        for(int i = num-1; 2 < i;i--){
        if(IsPrime(i) == true){
           cout<<i<<" ";
            break;
        }
    }
    for(int k = num+1;k < 50022; k++){
        if(IsPrime(k) == true){
            cout<<k<<endl;
            break;
        }
    }
    
    }

}

C++: #include<bits/stdc++.h>
using namespace std;
bool flg[500000]{false};
int main(void){
	int n;
	int i,j;
	
	for(i=2;i*i<=500000;i++){
		if(!flg[i]){
			for(j=2;i*j<=500000;j++){
				flg[i*j]=true;
			}
		}
	}
	//for(i=2;i*i<=500000;i++)	if(!flg[i])	cout<<i<<endl;
	while(1){
		cin>>n;
		if(cin.eof())	break;
		i=n-1;
		while(1){
			if(!flg[i]){
				cout<<i<<" ";
				break;
			}
			i--;
		}
		i=n+1;
		while(1){
			if(!flg[i]){
				cout<<i<<endl;
				break;
			}
			i++;
		}
	}
	return 0;
}

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

int main(){
  int table[50001]={};
  for(int i=2; i<1000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=50001; 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;
  }
}

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

int main()
{
  const int MAX_P = 60000;
  bool p[MAX_P];
  for (int i = 0; i < MAX_P; ++i)
    p[i] = true;
  p[0] = p[1] = false;

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

  vector<int> prime;
  for (int i = 0; i < MAX_P; ++i) {
    if (p[i])
      prime.push_back(i);
  }

  int n;
  while (~scanf("%d", &n)) {
    printf("%d %d\n", *(lower_bound(prime.begin(), prime.end(), n)-1),
	   *upper_bound(prime.begin(), prime.end(), n));
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
 
int main(){
  bool is_prime[50019];
 
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<50019;i++){
    is_prime[i] = true;
  }
 
  for(int i=2;i*i<50019;i++){
    if(is_prime[i]){
      for(int j=i*i;j<50019;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 <stdio.h>
int IsPrime(int n)
{
	int i;
	if(n<2)return 0;
	if(n==2)return 1;
	if(n%2 == 0)return 0;
	for(i=3; i*i<=n; i++)
		if(n%i == 0)return 0;
	return 1;
}

int main(void)
{
	int n, tmp;
	while(scanf("%d", &n)!=EOF)
	{
		tmp=n-1;
		while(!IsPrime(tmp))tmp--;
		printf("%d ",tmp);
		tmp=n+1;
		while(!IsPrime(tmp))tmp++;
		printf("%d\n", tmp);
	}
	return 0;
}

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


#define N 50000

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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

const int SIZE = 50000;

int main(int argc, char *argv[]) {
	// make sieve
	vector<bool> sieve(SIZE, true);
	vector<int> prime;
	for (int i = 2; i < SIZE; i++) {
		if (sieve[i]) {
			prime.push_back(i);
			//printf("%d\n", i);
			for (int j = i+i; j < SIZE; j+=i) {
				sieve[j] = false;
			}
		}
	}
	sort(prime.begin(), prime.end());
	// load data
	int rcv;
	const int prime_size = static_cast<int>(prime.size());
	while (EOF != fscanf(stdin, "%d", &rcv)) {
		for (int i = 0; i < prime_size; i++) {
			if (prime[i] > rcv) {
				if (prime[i-1] != rcv)
					printf("%d %d\n", prime[i-1], prime[i]);
				else
					printf("%d %d\n", prime[i-2], prime[i]);
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> sosu(60000, 1);

void eratos() {
  for(int i = 2; i < 30000; i++) {
    sosu[2*i] = 0;
  }
  for(int i = 5; i*i < 60000; i++) {
    if(sosu[i] == 1) {
      for(int j = 1; i*j < 60000; j++) {
	sosu[i*(j+2)] = 0;
      }
    }
  }
}

int main() {
  eratos();

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