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 <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
 
using namespace std;
 
int main(){
    int n;
    int nums[6000] = {0};
    
    int qf = 0;
    int qe = 0;
    for(int i = 2; i <= 50000; i++){
        bool f = false;
        for(int qe = 0; qe < qf; qe++ ){
            if(i < nums[qe] * nums[qe]) break; //この行で速さが変わる（爆速）
            if(i % nums[qe] == 0) {
                f = true;
                break;
            }
        }
        if(!f) { nums[qf] = i; qf++; }
    }

    while(cin >> n){
        int index = 0;
        while(true){
            if(nums[index + 1] == n) {
                cout << nums[index] << " " << nums[index + 2] << endl;
                break;
            }
            if(nums[index] <= n && nums[index + 1] >= n) {
                cout << nums[index] << " " << nums[index + 1] << endl;
                break;
            }
            index++;
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

const int N = 6e4L + 11;
int p[N];

int main() {
	iota(p, p + N, 0);
	for(int i = 2; i < N; i ++) if(p[i] == i)
		for(int j = i; j < N; j += i) p[j] = i;
	ios :: sync_with_stdio(0);

	for(int x; cin >> x; ) {
		for(int i = x - 1; ; i --)
			if(p[i] == i) {
				cout << i << ' ';
				break;
			}
		for(int i = x + 1; ; i ++)
			if(p[i] == i) {
				cout << i << '\n';
				break;
			}
	}

	return 0;
}

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

bool Judge_Prime_Number( int x )
{
    bool j = true;
    for( int i = 2; i <= sqrt(x); i++ )
    {
        if( x % i == 0 )
        {
            j = false;
            break;
        }
    }
    return j;
}

int main()
{
    int a;

    cin >> a;

    int min = a - 1, max = a + 1;

    while( Judge_Prime_Number(min) == false )
        min--;
    while( Judge_Prime_Number(max) == false )
        max++;
    
    cout << min << " " << max << endl;

    return 0;
}

C++: #include <cstdio>
#include <algorithm>
using namespace std;
int main() {
	int n;
	bool isprime[70001];
	int prime[35000];
	int pnum = 0;
	fill(isprime, isprime+70001, true);
	isprime[0] = isprime[1] = false;
	for (int i=2; i<70001; i++) {
		if (isprime[i]) {
			for (int j=i+i; j<70001; j+=i) isprime[j] = false;
		}
	}
	for (int i=2; i<70001; i++) {
		if (isprime[i]) {
			prime[pnum++] = i;
		}
	}
/*	for (int i=0; i<100; i++) {
		printf("%d ",prime[i]);
	}
	printf("\n");
*/
	while (scanf("%d", &n)!=EOF) {
		int a, b;
		for (int i=0; i<35000; i++) {
			if (prime[i] > n) {
				a = prime[i-1];
				b = prime[i];
				break;
			} else if (prime[i] == n) {
				a = prime[i-1];
				b = prime[i+1];
				break;
			}
		}
		printf("%d %d\n", a, b);
	}
}

C++: #include <iostream>
using namespace std;
bool p[50100];
int main()
{
  int i,j;
  for(i=2;i*i<50100;i++){
    if(!p[i]){
      for(j=i*2;j<50100;j+=i){
	p[j] = true;
      }
    }
  }
  while(cin >> i,i){
    for(j=i-1;j>1;j--){
      if(!p[j]) {
	cout << j << " ";
	break;
      }
    }
    for(j=i+1;j<50100;j++){
      if(!p[j]) {
	cout << j << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

int main()
{

	vector<int> prime;
	prime.push_back(2);
	prime.push_back(3);
	prime.push_back(5);

	for(int i=7;i<=60000;i+=2){
		bool ok=true;
		for(int j=0;prime[j]*prime[j]<=i && ok;j++){
			if(i%prime[j]==0) ok=false;
		}
		if(ok) prime.push_back(i);
//		if(ok) cout<<i<<endl;
	}

	int n;
	while(cin>>n){

		auto u=upper_bound(prime.begin(),prime.end(),n);
		auto l=u-1;

		if(*l==n) l--;

		cout<<*l<<" "<<*u<<endl;

	}


	return 0;
}

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


bool is_prime(int n)
{
	for(int i=2;i*i<n+1;i++){
		if(n%i==0)
			return false;
	}
	return n != 1;
}

int main()
{
	int n;
	while(cin >> n){
		int	tmp = n-1;
		while(1){
			if(is_prime(tmp)){
				cout << tmp << " ";
				break;
			}
			tmp--;
		}
		tmp = n+1;
		while(1){
			if(is_prime(tmp)){
				cout << tmp << endl;
				break;
			}
			tmp++;
		}
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <ctime>
using namespace std;

#define rep(i,a,n) for(int i=a; i<n; i++)
#define repr(i,a,n) for(int i=a; i>=n; i--)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 999999999

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long int ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P a, const P b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

vector<int> erat(int n) {
    vector<int> primes(n);
    for (int i = 2; i < n; ++i) primes[i] = i;
    for (int i = 2; i*i < n; ++i)
        if (primes[i])
            for (int j = i*i; j < n; j+=i) primes[j] = 0;
    // ?´???°?????????vector???????´?????????´????????\?????????????????? (0 ??§??????????´??????¨??????)
    primes.erase(remove(primes.begin(), primes.end(), 0), primes.end());
    return primes;
}

int main() {
    vector<int> v = erat(55000);

    int n;
    while(cin >> n) {
        int d = lower_bound(v.begin(), v.end(), n) - v.begin();
        if(v[d] == n) printf("%d %d\n",v[d-1],v[d+1]);
        else printf("%d %d\n",v[d-1], v[d]);
    }
    return 0;
}

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

#define SIZE 100000
bool prime[SIZE];

int main(){
    memset( prime, 0, sizeof(prime) );
    for( int i=2; i<(int)sqrt(SIZE)+1; i++ ){
        if( !prime[i] ){
            for( int j=i+i; j<SIZE; j+=i ){
                prime[j] = true;
            }
        }
    }

    int n;
    while( cin >> n ){
        for( int i=n-1; i>=3; i-- ){
            if( !prime[i] ){
                cout << i;
                break;
            }
        }
        for( int i=n+1; i<SIZE; i++ ){
            if( !prime[i] ){
                cout << " " << i << endl;
                break;
            }
        }
    }
    return 0;
}