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

const int SIZE = 50030;
bool isprime[SIZE + 1] = {0};
vector<int> prime;
void make_prime(){
    isprime[1] = true;
    isprime[0] = true;
    for(int i = 2; i <= SIZE; i++){
        if(isprime[i]) continue;
        for(int j = i * 2; j <= SIZE; j += i) isprime[j] = true;
        prime.push_back(i);
    }
}

int main(){
    make_prime();
    int n;
    while(cin >>n){
        int min, max;
        for(min = n - 1; isprime[min] != false; min--) ;
        for(max = n + 1; isprime[max] != false; max++) ;
        cout <<min <<" " <<max <<endl;
    }
    return 0;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define PRIM 50021

bool prim[50022];
int a_prime[500022];

int main(){
	memset(prim, true, sizeof(prim));
	int N;
	prim[0] = false;
	FOR(i, 1, sqrt(PRIM)) {
		if(prim[i]) {
			for(int j = (i + 1); (i + 1) * j <= PRIM; ++j) {
				prim[(i + 1) * j - 1] = false;
			}
		}
	}
	int cnt = 0;
	rep(i, PRIM) {
		if(prim[i]) a_prime[cnt++] = i + 1;
	}
	while(scanf("%d", &N)) {
		rep(i, cnt) {
			if(a_prime[i + 1] >= N) {
				printf("%d ", a_prime[i]);
				break;
			}
		}
		rep(i, cnt) {
			if(a_prime[i] > N) {
				printf("%d\n", a_prime[i]);
				break;
			}
		}
	}
	return 0;
}

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



bool judgePrimenum(int n){

	int sqr = sqrt((double)n);

	if(n%2 == 0)return false;

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

	return true;
}




int main(){
	int n, min=0, max=0, i=1;
	while(cin >> n){
		min=0;max=0;i=1;

		while(min==0 || max==0){
			if( max==0 && judgePrimenum(n+i) )max=n+i;
			if( min==0 && judgePrimenum(n-i) )min=n-i;
			++i;
		}

		cout << min << " " << max << endl;
	}
	return 0;
}

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

int main(){
  bool  prime[100000];
  for(int i=0;i<100000;i++){
    prime[i]=true;
  }
  prime[0]=prime[1]=false;
  for(int i=2;i<1000;i++){
    for(int j=i*2;j*i<100000;j+=i){
      prime[j]=false;
    }
  }
  int n;
  int cnt1=-1,cnt2=-1;
  while(cin>>n){
    for(int i=0;i<n;i++){
      if(prime[i])cnt1=i;
    }
    for(int i=n+1;;i++){
      if(prime[i]){
	cnt2=i;
	break;
      }
    }
    cout<<cnt1<<" "<<cnt2<<endl;
  }
  return 0;
}

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

bool is_composite[100001];
vector<int> primes;

int main() {
  for (int i=2; i<=100000; i++) {
    if (!is_composite[i]) {
      primes.push_back(i);
      for (int j=i+i; j<=100000; j+=i) is_composite[j] = true;
    }
  }

  while (1) {
    int n;
    if (scanf("%d", &n) != 1) return 0;
    auto itr1 = lower_bound(primes.begin(), primes.end(), n)-1;
    auto itr2 = upper_bound(primes.begin(), primes.end(), n);
    printf("%d %d\n", *itr1, *itr2);
  }
}

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>
#include<vector>
int main()
{
	std::vector<bool>is_prime(50020, true);
	const int root = static_cast<int>(floor(sqrt(50021)));
	for (int i = 0; i <= root - 2; i++)
	{
		if (is_prime[i])
		{
			for (int j = i + 2; (i + 2) * j < 50021; j++)
			{
				is_prime[(i + 2) * j - 2] = false;
			}
		}
	}
	for (int n; std::cin >> n;)
	{
		for (int i = n - 2 - 1;; i--)
		{
			if (is_prime[i])
			{
				std::cout << i + 2 << ' ';
				break;
			}
		}
		for (int i = n - 2 + 1;; i++)
		{
			if (is_prime[i])
			{
				std::cout << i + 2 << std::endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int lim = 1e5;

int main(){
	vector<bool> prime(lim, true);
	prime[0] = prime[1] = false;
	for(int i=2; i*i<lim; i++){
		if(prime[i]){
			for(int j=i*2; j<lim; j+=i){
				prime[j] = false;
			}
		}
	}

	int n;
	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;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
 
using namespace std;
 
int main(){
    int n;
    int nums[6000] = {0};
    
    int qf = 0;
    int qe = 0;
    for(int i = 2; i <= 50100; i++){
        bool f = false;
        for(int qe = 0; qe < qf; qe++ ){
            if(i < nums[qe] * nums[qe]) break; //この行で速さが変わる（爆速）
            if(i % nums[qe] == 0) {
                f = true;
                break;
            }
        }
        if(!f) { nums[qf] = i; qf++; }
    }

    while(cin >> n){
        int index = 0;
        while(true){
            if(nums[index + 1] == n) {
                cout << nums[index] << " " << nums[index + 2] << endl;
                break;
            }
            if(nums[index] <= n && nums[index + 1] >= n) {
                cout << nums[index] << " " << nums[index + 1] << endl;
                break;
            }
            index++;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#define N 50022
using namespace std;

int main(){

	int pn[N], n, p;

	fill(pn, pn+N, 1);
	for(int i=2; i<N; i++){
		if(pn[i] == 1){
			for(int j=2; (p = i * j)<N; j++){
				pn[p] = 0;
			}
		}
	}
	
	while(cin >> n){
		for(int i=n-1; i>0; i--){
			if(pn[i] == 1){
				cout << i << " ";
				break;
			}
		}
		for(int i=n+1; i<N; i++){
			if(pn[i] == 1){
				cout << i << endl;
				break;
			}
		}		
	}

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

    int n_prime[N];
    int cnt = 0;
    for(int i=0;i<N;i++){
      if(is_prime[i]){
        n_prime[cnt++] = i;
      }
    }


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

}