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

      if(p[i]) n = i;
    }
  }
}

C++: #include<iostream>
#include<math.h>

using namespace std;

int prime[60000];

void makeprimechart(void);

int main(){

  makeprimechart();

  int n, max, min;

  while(cin >> n){

    for(int i = n+1; i < 60000; i++){
      if(prime[i] == 1){
	max = i;
	break;
      }
    }
    
    for(int i = n-1; i > 1; i--){
      if(prime[i] == 1){
	min = i;
	break;
      }
    }
    
    cout << min << " " << max << endl;
  } 
  return 0;
  
}


void makeprimechart(void){

  for(int i = 0; i < 60000; i++){
    prime[i] = 1;
  }

  prime[0] = 0;
  prime[1] = 0;


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

C++: asdf

C++: #include<stdio.h>
#include<math.h>

int main(){
	int num;
	int ans=0;
	int i,j,k;
	int box[100000];
		
	while(scanf("%d",&num)!=EOF){
		
		for(i=2;i<=80000;i++)box[i]=1;
		
		for(i=2;i<=sqrt(80000);i++){
			if(box[i]==1){
				for(j=2;i*j<=80000;j++){
					box[i*j]=0;
				}
			}
		}
		
		
		for(i=num-1;i>=3;i--)if(box[i]==1){
			printf("%d ",i);
			break;
		}
		for(i=num+1;i<=80000;i++)if(box[i]==1){
			printf("%d\n",i);
			break;
		}
		ans=0;
	}
	return 0;
}

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

int main() {

int a[50010];
a[0]=0;
a[1]=0;
a[2]=1;
a[3]=1;
a[5]=1;
for(int kk=2;kk<25001;kk++){
	a[2*kk]==0;
}
for(int k=3;k<25000;k++){
	int n,q=1;
	n=sqrt(2*k+1);
	for(int j=1;j<=n/2;j++){
	if(	(2*k+1)%(2*j+1)==0){
		q=0;
	}
	}
a[2*k+1]=q;
}
int p;
while(cin>>p){
	int l=1,m=1;
	while(a[p+l]==0){
		l=l+1;
	}
	while(a[p-m]==0){
		m=m+1;
	}
	cout<<p-m<<" "<<p+l<<endl;
}

	return 0;
}

C++: #include<iostream>
#include<math>
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>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
int main() {
	int n,a,b,c;
	while(cin>>n){
		if(n==3){
			cout<<2<<" "<<5<<endl;
		}
		else{
		for(int i=n-1;i>1;i--){
			for(int j=2;j<i;j++){
				c=j;
				if(i%j==0){
					break;
				}
			}
			if(c==i-1){
				a=i;
				break;
				}
		}
		for(int i=n+1;i<100000;i++){
			for(int j=2;j<i;j++){
				c=j;
				if(i%j==0){
					break;
				}
				}
			if(c==i-1){
				b=i;
				break;			
			}
		}
		cout<<a<<" "<<b<<endl;
	}
  }
}

C++: #include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)

static const double PI=6*asin(0.5);
typedef complex<double> P;
typedef long long ll;


bool prime[6010];
vector <int> pri;

int main(){
	memset(prime,0,sizeof(prime));
	rep(i,6000){
		prime[i]=true;
	}
	prime[1]=false;
	prime[0]=false;
	for(int i=1;i*i<6000;i++){
		if(prime[i]){
			//cout<<i<<" ";
			for(int j=i*i;j<6000;j+=i){
				prime[j]=false;
			}
		}
	}
	rep(i,6000){
		if(prime[i]) pri.push_back(i);
	}
	
	int n;
	while(cin>>n){
		int smo,lar;
		rep(i,6000){
			if(pri[i]<n){
			}
			else{
				if(prime[n]==true){
					smo=pri[i-1];
					lar=pri[i+1];
				}
				else{
					smo=pri[i-1];
					lar=pri[i];
				}
				break;
			}
		}
		cout<<smo<<" "<<lar<<endl;
	}
	
	return 0;
}

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

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

C++: const int MAX_NUM = 100000000;
bool prime_number[MAX_NUM];
 
void prime_create() {
    fill(prime_number, prime_number + MAX_NUM, true);
    prime_number[0] = prime_number[1] = false;
 
    for(int i = 2; i < MAX_NUM; i++) {
        if(prime_number[i])
        for(int j = 2; i*j < MAX_NUM; j++) {
            prime_number[i*j] = false;
        }
    }
}

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[70001];

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(70000);
	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;
}