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 <math.h> 
using namespace std;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
      {
        if (num % i == 0)
	  {
            // 素数ではない
            return false;
	  }
      }

    // 素数である
    return true;
}

int main(void){

  int n;

  while(cin >> n){
    int max_prime;
    int min_prime;
  
    for(int i=n-1;i>1;i--){
      if(IsPrime(i)){
	max_prime=i;
	break;
      }
    }

    for(int j=n+1;j<50001;j++){
      if(IsPrime(j)){
	min_prime=j;
	break;
      }
    }

    cout << max_prime << " " << min_prime << endl;

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

	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>
#include<vector>
#include<cmath>
#include<cstdio>

using namespace std;

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

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

  
  for(i=2;i*i<50001;i++){
    if(prime[i]==0){
      for(j=i*2;j<50001;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<50001;i++){
      if(prime[i]==0){
	cout << i << endl;
	break;
      } 
    }
  }
  return 0;
}

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

bool prime[MAX];
void calcPrime(){
	for(int i = 2; i < MAX; i++) prime[i] = true;
	for(int i = 2; i < MAX; i++){
		if( prime[i] ){
			for(int j = i+i; j <= MAX; j += i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	int n;
	calcPrime();
	while( cin >> n ){
		int under = -1, over = -1;
		for(int d = n, u = n; 0 < d || u < MAX; ){
			if( 0 < d ) d--;
			if( u < MAX ) u++;
			if( under != -1 && over != -1 ) break;
			if( prime[d] ) under = d;
			if( prime[u] ) over = u;
		}
		cout << under << " " << over << endl;
	}
}

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

using namespace std;
bool IsPrime[60000];
vector<int> Prime;

void PrimeCalc()
{
	for(int i = 0; i < 60000; ++i)
	{
		IsPrime[i] = true;
	}
	IsPrime[0] = IsPrime[1] = false;
	for(int i = 2; i < 60000; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < 60000; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	PrimeCalc();
	int n;
	while(~scanf("%d", &n))
	{
		int count = 0;
		while(n > Prime[count])
		{
			++count;
		}
		cout << Prime[count - 1] << " ";
		if(IsPrime[n])
		{
			++count;
		}
		cout << Prime[count] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

const int MAXN = 50001;

bool prime[MAXN] = {true, true};

int main()
{
  for (int i = 2; i * i < MAXN; i++){
    for (int j = i * i; j < MAXN; j += i){
      prime[j] = true;
    }
  }

  int n;
  
  while (~scanf("%d", &n)){
    for (int i = n - 1; i >= 2; i--){
      if (!prime[i]){
        printf("%d ", i);
        break;
      }
    }
    for (int i = n + 1; i < MAXN; i++){
      if (!prime[i]){
        printf("%d\n", i);
        break;
      }
    }
  }

  return (0);
}

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

int main(){
  bool a[1000000];

  a[0]=a[1]=false;
  for(int i=2;i<1000000;i++){
    a[i]=true;
  }

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

  int min,max;

  while(true){
    int m;
    cin>>m;

    if(cin.eof()){
      break;
    }

    for(int i=3;i<m;i++){
      if(a[i]){
        max=i;
      }
    }

    for(int i=m+1;i<=1000000;i++){
      if(a[i]){
        min=i;
        break;
      }
    }

    if(m==3){
      max=2;
    }

    cout<<max<<' '<<min<<endl;

  }

  return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

int main()
{
	int n;
	while(cin >> n)
	{
		for(int i = n - 1; ; i--)
		{
			bool flag = true;
			for(int j = 2; j * j <= i; j++)
			{
				if(i % j == 0)
				{
					flag = false;
					break;
				}
			}
			if(flag)
			{
				cout << i << " ";
				break;
			}
		}

		for(int i = n + 1; ; i++)
		{
			bool flag = true;
			for(int j = 2; j * j <= i; j++)
			{
				if(i % j == 0)
				{
					flag = false;
					break;
				}
			}
			if(flag)
			{
				cout << i << endl;
				break;
			}
		}
	}
}

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<iostream>
#include<math.h>
using namespace std;

#define MAX 1000000

int main(){

	bool p[MAX+1];
	int i,j,n;

	p[0]=false;
	p[1]=true;
	for(i=2; i<=MAX; i++){
		p[i] = true;
	}
	for(i=2; i<=sqrt(MAX)+1; i++){
		if(p[i]){
			for(j=i*2; j<=MAX; j=j+i){
				p[j] = false;
			}
		}
	}
	
	while(cin >> n){
		for(int i=n-1 ; i>=0 ; i--){
			if(p[i]){
				cout << i << " " ;
				break;
			}
		}
		for(int i=n+1 ; i<MAX ; i++){
			if(p[i]){
				cout << i << endl ;
				break;
			}
		}
	}
}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
int p[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  loop(i,2,M){
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n){
    int i = n - 1;
    while(!p[i--]);cout<<++i<<" ";
    i = n + 1;
    while(!p[i++]);cout<<--i<<endl;
  }
}