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;
 
bool f(int p) {
    for (int i=2; i*i<=p; i++) {
        if (p % i == 0) return false;
    }
    return true;
}
 
int main() {
    int N;
    while (cin >> N) {
        int p1, p2;
        for (p1=N-1; ; p1--) if (f(p1)) break;
        for (p2=N+1; ; p2++) if (f(p2)) break;
        cout << p1 << " " << p2 << endl;
    }
    return 0;
}

C++: //06
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n;){
    for(int m=n-1;;m--){
      int i;
      for(i=2;i<m;i++){
	if(m%i==0)break;
      }
      if(!(i<m)){
	cout<<i<<' ';
	break;
      }
    }
    for(int m=n+1;;m++){
      int i;
      for(i=2;i<m;i++){
	if(m%i==0)break;
      }
      if(!(i<m)){
	cout<<i<<endl;
	break;
      }
    }
  }
  return 0;
}

C++: //エラトステネスのふるいを使う
#include<iostream>
#include<cmath>

using namespace std;

int main(void){
	int i,min,so,low,high;
	double data[60000],max,cnt=0;

	//素数を配列に埋め込む
	for(i=2;i<60000;i++)
		data[i]=1;
	min=2;
	max=60000;
	while(1){
		if(sqrt(max)<min)	break;
		for(i=min;i<max;i++){
			if(i%min==0){
				data[i]=0;
			}
		}
		data[min]=1;
		for(i=min+1;i<60000;i++){
			if(data[i]==1){
				if(cnt==0)	min=i;
				else	max=i;
				cnt=1;
			}
		}
		cnt=0;
	}

	while(cin>>so){
		for(i=2;i<60000;i++){
			if(data[i]==1){
				if(so>i)	low=i;
				if(so<i){
					high=i;
					cnt=1;
				}
			}
			if(cnt==1)	break;
		}
		cout<<low<<' '<<high<<endl;
		cnt=0;
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <functional>
#include <sstream>
#include <complex>
#include <climits>
using namespace std;

#define REP(i,a,n) for(int i=(a);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define EPS 1e-8

bool primes[60000];
void make_prime(){
	primes[0]=primes[1]=true;
	for(int i=2; i*i<=60000; i++)if( !primes[i] )
		for(int j=i*2; j<60000; j+=i)primes[j]=true;
}
int main(){
	int n,min_p,max_p;
	make_prime();
	while(~scanf("%d",&n)){
		//min
		for(int i=n-1; i>1; i--)if( !primes[i] ){	min_p = i; break; }
		//max
		for(int i=n+1; i<60000; i++)if( !primes[i] ){ max_p=i; break; }
		printf("%d %d\n",min_p,max_p);
	}
	return 0;
}

C++: //まだ解けていない



//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

bool p[55000];

void prime() {
  fill(p, p+55000, true);
  p[0] = false;
  p[1] = false;

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

int main() {
  int n, min, max;
  prime();
  
  while(cin >> n) {
    max = 2;
    for(int i = 3; i < n; i++) {
      if(p[i] && max < i) max = i;
    }
    for(int i = n+1; i < 55000; i++) {
      if(p[i]) {
	min = i;
	break;
      }
    }
    cout << max << ' ' << min << endl;
  }
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> sosu(50000, 1);

void eratos() {
  for(int i = 2; i*i < 50000; i++) {
    if(sosu[i] == 1) {
      for(int j = 2; i*j < 50000; j++) {
	sosu[i*j] = 0;
      }
    }
  }
}

int main() {
  eratos();

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

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

bool isp[1000000]={};


void makeEra(){
    for(int i=2;i<=1000;i++){
        if( isp[i] ){
            for(int j=2;j<=1000000/i;j++){
                isp[i*j]=false;
            }
        }
    }
}


int main(){
    rep(i,1000000)isp[i]=true;
    isp[0]=isp[1]=false;
    makeEra();
    
    int n;
    while(cin>>n){
        for(int i=n-1;;i--){
            if(isp[i]){
                cout<<i;
                break;
            }
        }
        cout<<" ";
        for(int i=n+1;;i++){
            if(isp[i]){
                cout<<i;
                break;
            }
        }
        cout<<endl;
    }
}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
bool prime[50022];
void eratos()
{
	memset(prime,true,sizeof(prime));
	prime[0]=false;
	prime[1]=false;
	for(int i=2;i*i<50022;i++)
	{
		if(!prime[i])continue;
		for(int j=i*2;j<50022;j+=i)
		{
			prime[j]=false;
		}
	}
	return;
}
int main()
{
	int n,k,s;
	eratos();
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=n-1;;i--)
		{
			if(prime[i])
			{
				k=i;
				break;
			}
		}
		for(int i=n+1;;i++)
		{
			if(prime[i])
			{
				s=i;
				break;
			}
		}
		printf("%d %d\n",k,s);
	}
	return 0;
}