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;
int main(){
  bool num[10001]={false};
  for(int i=2; i<100; i++) if(!num[i]) for(int j=i*i; j<10001; j+=i) num[j] = true;
  for(int n; cin >>n;){
    for(int i=n-1;;i--) if(!num[i]){cout <<i<<" ";break;}
    for(int i=n+1;;i++) if(!num[i]){cout <<i<<endl;break;}
  }
  return 0;
}

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

using namespace std;

int main(void){
  int prime[60000],i,j,x;

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

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

  while(scanf("%d",&x)!=EOF){
    for(i=x-1;i>=2;i--){
      if(prime[i]==0){
	cout << i <<" ";
	break;
      }
    }
    
    for(i=x+1;i<60000;i++){
      if(prime[i]==0){
	cout << i << endl;
	break;
      } 
    }
  }
  return 0;
}

C++: j,i,n,x=0;int main(){while(scanf("%d",&n)!=EOF){for(i=n-1;;i--){for(j=2;j*j<=i;j++){	if(j!=i){if(i%j==0){x=1;}}}if(x==0) {printf("%d ",i); goto qq;}
x=0;}q:for(i=n+1;;i++){for(j=2;j*j<=i;j++){	if(j!=i){if(i%j==0){x=1;}}}if(x==0) {printf("%d\n",i); goto rr;}
x=0;} r:; }return 0;}

C++: #include<stdio.h>
int main(void){
  
  int i,j;
  int num[50001]={0,0,1};
  int sosu[5000]={2};
  int count=1;
  
  for(i=3;i<50001;i+=2){
    if(num[i]==1)
      continue;
    for(j=3*i;j<50001;j+=i*2)
      num[j]=1;
  }
  for(i=3;i<50001;i+=2){
    if(num[i]!=1){
      sosu[count]=i;
      count++;
    }
  }

  int in;
  while(scanf("%d",&in)!=EOF){
    for(i=0;i<50000;i++){
      if(in<sosu[i])
	break;
    }
    printf("%d %d",sosu[i-2],sosu[i]);
  }

  return 0;
}

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

const long MAX_N=60000;
bool isPrime[MAX_N];

int main(){
	//素数テーブルの設定
	for(long i=2; i<=MAX_N; ++i)
		isPrime[i]=true;
		
	for(long i=2; i<=MAX_N; ++i){
		if(isPrime[i]){
			for(long j=2; i*j<=MAX_N; ++j) isPrime[i*j]=false;
		}
	}
	
	//実際の問題処理
	long n;
	
	while( scanf("%ld", &n) != EOF ){
		long i=n-1;
		while(1){
			if(isPrime[i]){
				printf("%ld ",i);
				break;
			}
			--i;
		}
		
		i=n+1;
		
		while(1){
			if(isPrime[i]){
				printf("%ld\n",i);
				break;
			}
			++i;
		}	
	} 

	return 0;
}

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

using namespace std;
bool isPrime(int num);

int main(){
	int n;
	while(cin >> n, n){
		for(int i = n-2; i >= 3; i -= 2){
			if(isPrime(i) ){
				cout << i;
				break;
			}
		}
		
		for(int i = n+2; i <= 50000; i += 2){
			if(isPrime(i)){
				cout << " " << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

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

void sieve(int n,vector<char>& v){
    v.resize(n);
    fill(v.begin(),v.end(),true);
    v[0]=v[1]=false;

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

int main(){
    vector<char> prime_list;
    int n;

    sieve(60000,prime_list);
    while(cin>>n){
        int s,b;
        for(s=n-1;!prime_list[s];s--);
        for(b=n+1;!prime_list[b];b++);

        cout<<s<<" "<<b<<endl;
    }

    return 0;
}

C++: #include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <sstream>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <iterator>
#include <stack>
#include <list>
using namespace std;
#define INF 100000000
typedef long long int lli;
typedef pair<int,int> P;

bool f[60000];

int main(){
	for(int i=0; i<60000; ++i){
		f[i] = true;
	}
	for(int i=2; i*i<60000; ++i){
		if(f[i]){
			for(int j=2; j*i<60000; ++j){
				f[i*j]=false;
			}
		}
	}
	int n;
	while(cin >> n){
		int over,under;
		for(int i=n-1; i>=2; --i){
			if(f[i]){
				under=i;
				break;
			}
		}
		for(int i=n+1; i<60000; ++i){
			if(f[i]){
				over=i;
				break;
			}
		}
		cout << under << " " << over << "\n";
	}
	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 = 3; i < sqrt(60000); i+=2) {
    if(sosu[i] == 1) {
      for(int j = 1; i*(j+2) < 60000; j++) {
	sosu[i*(j+2)] = 0;
      }
    }
  }
}

int main() {
  eratos();

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

C++: #include <stdio.h>

int isprime(int x){
  if(!(x&1)) return 0;
  
  int i;
  for(i=3;i*i<x;i+=2){
    if(!(x%i)) return 0;
  }
  return 1;
}

int main(){
  int n;
  while(scanf("%d", &n)!=EOF){
    int i;

    int bottom=0;
    for(i=n-1;i>=2;i--) if(isprime(i)) bottom = i,i=0;

    int upper=0;
    for(i=n+1;i<=6000;i++) if(isprime(i)) upper=i,i=7000;

    printf("%d %d\n", bottom, upper);
  }
}

C++: #include<stdio.h>
#include<iostream>
#include<list>
#include<map>
#include<vector>
#include<algorithm>
#include<string.h>
#include<bitset>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << x << endl;
using namespace std;

int main(){
    int it = 0, i = 0;
    bitset<51000> eratos;
    vector<int> prime;
    prime.push_back(2);

    range(j,2,51000)
        eratos[j] = 1;
    eratos[0] = 0;
    eratos[1] = 0;

    while(i < 51000){
        while(1){
            if(eratos[i] == 1){
                prime.push_back(i + 1);
                break;
            }
            i++;
        }
        for(int j = 2; prime[it] * j - 1 < 51000; j++){
            int num = prime[it] * j - 1;
            eratos[num] = 0;
        }
        it++; i++;
    }

    int input;
    while(cin >> input){
        rep(i, 5500){
            if(input < prime[i]){
                if(input > prime[i - 1])
                    cout << prime[i - 1];
                else
                    cout << prime[i - 2];
                cout << ' ' << prime[i];
                break;
            }
        }
    }
}

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

const unsigned LIMIT = 50050;

int main(){
	bool table[ LIMIT ] = { false };
	table[ 2 ] = true;
	for ( int i = 3; i < LIMIT; i += 2 ){
		table[ i ] = true;
	}
	for ( int i = 3; i < LIMIT; i += 2 ){
		if ( !table[ i ] ) continue;
		for ( int j = i + i; j < LIMIT; j += i ){
			table[ j ] = false;
		}
	}

	int n;
	while ( cin >> n ){
		for ( int i = n-1; i > 1; --i ){
			if ( table[ i ] ){
				cout << i;
				break;
			}
		}
		cout << " ";
		for ( int i = n+1; i < LIMIT; ++i ){
			if ( table[ i ] ){
				cout << i;
				break;
			}
		}
		cout << endl;
	}

	return 0;
}