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<bits/stdc++.h>
using namespace std;
int main()
{
    int num[50010],n,ma,anslow=0,anshigh=0;
    ma=sqrt(50010);
    for(int i=1;i<50010;i++)num[i]=0;
    for(int i=2;i<ma;i++){
        if(num[i]==0){
            for(int j=2;j*i<50010;j++)num[j*i]=1;
        }
    }
    while(cin>>n){
        for(int i=1;anslow==0||anshigh==0;i++){
            if(num[n-i]==0&&anslow==0)anslow=n-i;
            if(num[n+i]==0&&anshigh==0)anshigh=n+i;
        }
        cout<<anslow<<" "<<anshigh<<endl;
        anshigh=0;anslow=0;
    }
}

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

int prime[MAX],judge[MAX]={0};

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

int main(void){
  int n;

  p();
  while(cin >> n){
    int key = 0;
    while(1){
      if(n == prime[key]){
        cout << prime[key-1] << ' ' << prime[key+1] << endl;
        break;  
      }
      key++;
    }
  }

  return 0;
}

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

int prime[MAX+1];

void is_prime(){
  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;
      }
    }
  }
}

int main(void){
  int n;

  is_prime();

  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 <bits/stdc++.h>
#define rep(i, a) for (int i = 0; i < (a); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    bool is_prime[1000000];

    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(true){
        int n;
        cin >> n;
        if(cin.eof()){
            break;
        }
        int mn,mx;
        for(int i=2; i<=100000; i++){
            if(is_prime[i]){
                if(i < n){
                    mn = i;
                }else{
                    if(i != n){
                        mx = i;
                        break;
                    }
                }
            }
        }
        cout << mn << " " << mx << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define N (50000)

bool prime[N + 1];

int main()
{
	memset(prime, true, sizeof(prime));
	prime[0] = prime[1] = false;
	
	for (int i = 2; i * i <= N; i++){
		for (int j = i * i; j <= N; j += i){
			prime[j] = false;
		}
	}
	
	int n;
	while (~scanf("%d", &n)){
		int l = n - 1;
		while (!prime[l]) l--;
		int r = n + 1;
		while (!prime[r]) r++;
		printf("%d %d\n", l, r);
	}
	
	return 0;
}

C++: #include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip> 
#include <complex> 
#include <string>
#include <vector> 
#include <list>
#include <deque> 
#include <stack> 
#include <queue> 
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm> 
#include <numeric> 
#include <typeinfo> 
#include <cstdio>
#include <cstdlib> 
#include <cstring>
#include <cmath>
#include <climits> 
#include <ctime>

using namespace std;

bool is_prime[50001];

void sieve(int n){
	int p=0;
	int i,j;
	for(i=0;i<=n;i++)is_prime[i]=true;
	is_prime[0]=is_prime[1]=false;
	for(i=2;i<=n;i++){
		//is_prime[i]==true時
		if(is_prime[i]){
			for(j=2*i;j<=n;j+=i)is_prime[j]=false;
		}
	}
}

int main(void){
	sieve(50000);
	int a,b;
	bool ch=true;
	while(~scanf("%d",&a)){
		ch=true;
		b=a;
		while(ch){
			b--;
			if(is_prime[b]){
				printf("%d ",b);
				ch=false;
			}
		}
		ch=true;
		b=a;
		while(ch){
			b++;
			if(is_prime[b]){
				printf("%d\n",b);
				ch=false;
			}
		}
	}
	return 0;
}

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

#define prime 50021
#define Sprime 223

int main() {
	int sn, bn, n;
	bool not_prime[prime + 1];
	for (int i = 2; i <= Sprime; i++) {
		if (!not_prime[i]) {
			for (int j = i + i; j <= prime; j += i) {
				not_prime[j] = true;
			}
		}
	}
	while (cin >> n) {
		sn = bn = n;
		while (not_prime[--sn]);
		while (not_prime[++bn]);
		cout << sn << " " << bn << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;

#define MAX_N 50010

int prime[MAX_N];
bool is_prime[MAX_N + 1];

void sieve(int n){
	int p = 0;
	for(int i = 0; i <= MAX_N; i++) is_prime[i] = true;

	is_prime[0] = is_prime[1] = false;

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


	for(int i = 0; i < MAX_N; i++){

		if(prime[i] == n){
			cout << prime[i-1] << " " << prime[i+1] << endl;;
			break;
		}
		else if(prime[i] > n){
			cout << prime[i] << " " << prime[i-1] << endl;
			break;
		}
		else continue;
	}
}

int main(){
	int n;
	while(cin >> n){
		sieve(n);
	}
}

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<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 == 0)
        break;

      int i=0;
      while(i <= n/2){
      if(is_prime[n-i] && is_prime[n])
          counter++;
        i++;
      }
      cout << counter << endl;
      }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n){
    int math[100000]={0};
    math[1]=1;
    for(int i=2;i<100000;i++){
      int bell=i;
      while(bell+i<=100000){
	bell+=i;
	if(math[bell]==0){
	  math[bell]=1;
	}
      }
    }
    
    int hess=n;
    while(1){
      hess--;
      if(math[hess]==0){
	cout << hess << " ";
	break;
      }
    }
    
    hess=n;
    while(1){
      hess++;
      if(math[hess]==0){
	cout << hess << endl;
	break;
      }
    }
  }
    
  return (0);
}

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

int data[51111]={0};
int n;
char c[5];

int main(){

  data[0]=1;
  data[1]=1;

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

  while(scanf(" %s",c)!=EOF){

    n=atoi(c);

    for(int i=n-1;i>3;i--){
      if(data[i]!=1){
        cout << i << ' ';
        break;
      }
    }

    for(int i=n+1;i<50001;i++){
      if(data[i]!=1){
        cout << i << endl;
        break;
      }
    }

  }

  return 0;
}