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<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))

bool p[60001];

int main(){
	int n,s,l;
	p[0]=p[1]=1;
	reps(i,2,60000)if(!p[i])for(int j=i+i;j<=60000;j+=i)p[j]=1;
	while(~scanf("%d",&n)){
		for(int i=n-1;i>1;i--)if(!p[i]){s=i;break;}
		for(int i=n+1;i<60000;i++)if(!p[i]){l=i;break;}
		printf("%d %d\n",s,l);
	}
	return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
bool prime[50001];
int main()
{
  for(int i = 2;i <50001;i++){
    prime[i] = true;
  }
  prime[0] = false;
  prime[1] = false;
  for(int j = 2;j*j <50001;j++){
    if(prime[j]){
      for(int i =2*j;i <50001;i+=j){
	prime[i] = false;
      }
    }
  }
  int x;
  
  while(cin>>x){
 
    for(int i = x-1;i >1;i--){
      if(prime[i]){
	cout << i;
	break;
      }
    }
    bool flag = false;
    for(int i = x+1;i <50001;i++){
      if(prime[i]){
	cout <<" "<<i <<endl;
	flag = true;
	break;
      }
    }
    if(!flag){
      cout <<endl;
    }

  }
  return 0;
}

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

int main(){
	bool b[MAX];
	fill(b, b+MAX, false);b[0] = b[1] = true;
	for(int i = 2;i < MAX;i++){
		if(!b[i]){
			for(int j = 2;i*j < MAX;j++){
				b[i*j] = true;
			}
		}
	}
	
	int n, x, y;
	while(cin >> n, n){
		for(x = n-1;b[x];x--);
		for(y = n+1;b[y];y++);
		cout << x << " " << y << endl;
	}
	return 0;
}
/*
1
y eazqyp pnop pngtg ye obmpngt xmybp mr lygw
*/

C++: #include <iostream>
using namespace std;
 
int main(){
  bool is_prime[50004];
 
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<50004;i++){
    is_prime[i] = true;
  }
 
  for(int i=2;i*i<50004;i++){
    if(is_prime[i]){
      for(int j=i*i;j<50004;j=j+i){
        is_prime[j] = false;
      }
    }
  }
 
  while(true){
    int n;
    cin >> n;
 
    if(cin.eof())
        break;
 
    int high = n;
    int low = n;
 
    while(1){
      high = high+1;
      if(is_prime[high]){
        break;
      }
    }
 
    while(1){
      low = low-1;
      if(is_prime[low]){
        break;
      }
    }
 
    cout << low << " " << high << endl;
  }
 
  return 0;
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
	vector<int> prid(MAX);
	vector<int> pri(MAX);
	int k=0;
	for(int i=0;i<MAX;i++)
		prid[i]=1;
	prid[0]=0;
	prid[1]=0;
	for(int i=0;i*i<MAX;i++){
		if(prid[i]){
			for(int j=i*2;j<MAX;j+=i)
				prid[j]=0;
		}
	}
	for(int i=0;i<MAX;i++)
	if(prid[i])
	pri[k++]=i;
	int x;
	while(cin>>x){
		for(int i=0;i<MAX;i++)
		if(pri[i]>x){
			if(pri[i-1]==x)
			cout<<pri[i-2]<<' ';
			else cout<<pri[i-1]<<' ';
			cout<<pri[i]<<endl;
			
			break;
		}
	}
	return 0;
}

C++: #include <string>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <utility>
#include <algorithm>
#include <numeric>
#include <iostream>

using namespace std;
template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

bool b[60000];

int main()
{
	memset(b,1,sizeof(b));
	b[0] = b[1] = false;
	for (int i = 2; i < 300; i++)
		if(b[i]) for(int j = i * 2; j < 60000; j += i) b[j] = false;

	int n;
	while(cin>>n){
		int a,c;
		for (int i = n - 1; i >= 0 ; i--) if(b[i]){ a = i; break;}
		for (int i = n + 1; i < 60000; i++) if(b[i]){ c = i; break; }
		printf("%d %d\n",a,c);
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
#define N 60000
int main()
{
    int a[N]={0},n,i,j,z;
    for(i=2;i<=N/2;i++){
	if(a[i]==0){
	    for(j=2;j*i<=N;j++){
		a[i*j]=1;	     
    	    }
	}
    }
    while((cin>>n)!=0){
    	for(i=n-1;i>1;i--){
	    if(a[i]==0){
		cout<<i<<' ';
		break;		
	    }
	}
	
    	for(i=n+1;i<=N;i++){
	    if(a[i]==0){
		cout<<i<<endl;
		break;		
	    }
	}
    }
    return 0;	
}

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

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

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

using namespace std;
#define rep2(x,from,to) for(int x = (from); x < (to); ++(x))
#define rep(x,to) rep2(x,0,to)

int main() {
	bool p[90001];
	p[0] = p[1] = 0;
	rep2(i,2,90001) {
		p[i] = 1;
	}
	rep2(i,2,301) {
		if(p[i]) {
			for(int j = 2; i * j < 90001; j++) {
				p[i * j] = 0;
			}
		}
	}
	int n;
	while(cin >> n) { 
		int k = n - 1;
		while(!p[k]) {
			k--;
		}
		cout << k << " ";
		k = n + 1;
		while(!p[k]) {
			k++;
		}
		cout << k << endl;
	}
	return 0;
}

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

int main(){
  bool is_prime[52000];
  is_prime[0]=false;is_prime[1]=false;
  for(int i=2;i<52000;i++)is_prime[i]=true;
  for(int i=2;i<=sqrt(51999);i++){
    if(is_prime[i]){
      for(int j=2;i*j<=51999;j++)is_prime[i*j]=false;
    }
  }

  int n;
  while(cin>>n){
    int index=n-1;
    while(!is_prime[index]){
      index--;
    }
    cout<<index<<' ';

    index=n+1;
    while(!is_prime[index]){
      index++;
    }
    cout<<index<<endl;
  }
}

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

int primemax(int m);
int primemin(int m);

int main() {
	int n;
	while (scanf("%d",&n) != EOF) {
		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 = i;; 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 = i; ; j--) {
					if ((i%j)==0)break;
					if (j == 2) { result = i; return result; }
				}
			}
		}
}