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 <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <memory.h>
#include <cassert>

using namespace std;


#define all(c) ((c).begin()), ((c).end())
#define debug(c) cerr << "> " << #c << " = " << (c) << endl;
#define iter(c) __typeof((c).begin())
#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())
#define tr(i, c) for (iter(c) i = (c).begin(); i != (c).end(); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, a, b) for (int i = (int)(a); i <= (int)(b); i++)

#define mp make_pair
#define fst first
#define snd second
#define pb push_back


const double EPS = 1e-10;


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


int main() {
	int N = 60000;
	vi p(N, 1);
	p[0] = p[1] = 0;
	rep (i, N) if (p[i]) for(int j = i + i; j < N; j += i) p[j] = 0;
	for (int n; cin >> n; ) {
		for(int i = n - 1; ; i--) if (p[i]) {
			cout << i << ' ';
			break;
		}
		for(int i = n + 1; ; i++) if (p[i]) {
			cout << i << endl;
			break;
		}
	}
	
	return 0;
}

C++: #include <stdio.h>

int s[100000];

int main(void)
{
	int i;
	int j;
	int n;
	int a1, a2;
	
	for (i = 0; i <= 100000; i++){
		s[i] = 1;
	}
	s[0] = s[1] = 0;
	for (i = 2; i * i <= 100000; i++){
		if (s[i] == 0) continue;
		for (j = i * i; j <= 100000; j += i){
			s[j] = 0;
		}
	}
	while (scanf("%d", &n) != EOF){
		i = 1;
		a1 = a2 = 0;
		while (a1 == 0 || a2 == 0){
			if (s[n - i] == 1 && a1 == 0){
				a1 = n - i;
			}
			if (s[n + i] == 1 && a2 == 0){
				a2 = n + i;
			}
			i++;
		}
		printf("%d %d\n", a1, a2);
	}
	return (0);
}

C++: // 2020/05/18 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[60000];

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

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

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

		if(cin.eof())
			break;

		int pre;
		for(pre=n-1; !is_prime[pre]; pre--);

		int pos;
		for(pos=n+1; !is_prime[pos]; pos++);

		cout << pre << ' ' << pos << endl;
	}

	return 0;
}

C++: #include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

bool prime( int n )
{
	if ( n < 2 )
	{
		return false;
	}

	for ( int i = 2; i <= sqrt( n ); i++ )
	{
		if ( !( n % i ) )
		{
			return false;
		}
	}

	return true;
}

int main()
{
	int n;

	while (	cin >> n )
	{
		for ( int i = n - 1; 0 <= n; i-- )
		{
			if ( prime( i ) )
			{
				cout << i << ' ';
				break;
			}
		}

		for ( int i = n + 1; ; i++ )
		{
			if ( prime( i ) )
			{
				cout << i << endl;
				break;
			}
		}
	}

	return 0;
}

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

#define MAX_N 50000

using namespace std;

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

int main() {
	int n;
	int g, l, cur;
	vector<int> prime;
	for (int i = 2; i < MAX_N * 2; i++)
		if (isprime(i) == true)
			prime.push_back(i);
	while (cin >> n) {
		g = l = cur = 2;
		vector<int>::iterator it = prime.begin();
		while (it != prime.end()) {
			g = cur;
			cur = l;
			l = *it;
			if (l > n)
				break;
			it++;
		}
		cout << g << " " << l << endl;
	}
	return 0;
}

C++: #include<iostream>
int main(){
	int n;
	while(std::cin>>n){
		int a=n,b=n,e,d;
		while(1){
			int count=0;
			a--;
			for(int i=2;i<a/2;i++){
				if(a%i==0)count++;
			}
			if(count==0){
				d=a;
				break;
			}
		}
		while(1){
			int count=0;
			b++;
			for(int i=2;i<b/2;i++){
				if(b%i==0)count++;
			}
			if(count==0){
				e=b;
				break;
			}
		}
		std::cout<<d<<" "<<e<<std::endl;
	}
	return 0;
}

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

bool G[80001]={};

int main(){
	
	for(int i=3;i<80000;i+=2){G[i]=true;
		for(int j=3;j*j<=i;j++)
			if(i%j==0){G[i]=false;break;}
	}
	
	int N;
	while(cin>>N){
	
		for(int i=N-1;i>0;i--)
			if(G[i]==true){cout<<i;
		break;
		}
		cout<<" ";
		for(int i=N+1;i<80000;i++)
			if(G[i]==true){cout<<i<<endl;
		break;
		}
	}
	return 0;
}

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

int main() {

int a[50010];
a[0]=0;
a[1]=0;
a[2]=1;
a[3]=1;
a[5]=1;
for(int kk=2;kk<25001;kk++){
	a[2*kk]==0;
}
for(int k=3;k<25000;k++){
	int n,q=1;
	n=sqrt(2*k+1);
	for(int j=1;j<=n/2;j++){
	if(	(2*k+1)%(2*j+1)==0){
		q=0;
	}
	}
a[2*k+1]=q;
}

int p,l=1,m=1;
while(cin>>p){
	while(a[p+l]==0){
		l=l+1;
	}
	while(a[p-m]==0){
		m=m+1;
	}
	cout<<p-m<<" "<<p+l<<endl;
}

	return 0;
}

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

int main()
{
    int n;
    int max,first;
    bool flag=false;
    while(cin>>n,!cin.eof()){
        for(int i=2;i<n;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i/2<j){
                    max=i;
                    break;
                }
            }
        }
        cout<<max<<' ';
        bool flag=false;
        for(int i=n+1;;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i/2<j){
                    first=i;
                    flag=true;
                    break;
                }
            }
            if(flag)break;
        }
        cout<<first<<endl;
    }
    return 0;
}

C++: #include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int p[105000];
vector<int> prime;
int main(){
    for(int i = 2;i * i <= 105000;i++){
	if(p[i])continue;
	for(int j = i * i;j < 105000;j += i){
	    p[j] = 1;
	}
    }
    for(int i = 2;i < 105000;i++){
	if(p[i] == 0)
	    prime.push_back(i);
    }
    int n;
    while(cin >> n){
	int up = *(upper_bound(prime.begin(), prime.end(), n));
	int less = *(lower_bound(prime.begin(), prime.end(), n) - 1);
	cout << less << " " << up << endl;
    }
    return 0;
}

C++: #include<iostream>
int main(){
	int n;
	while(std::cin>>n){
		int a=n,b=n,e,d;
		while(1){
			int count=0;
			a--;
			for(int i=2;i<a/2;i++){
				if(a%i==0)count++;
			}
			if(count==0){
				d=a;
				break;
			}
		}
		while(1){
			int count=0;
			b++;
			for(int i=2;i<b/2;i++){
				if(b%i==0)count++;
			}
			if(count==0){
				e=b;
				break;
			}
		}
		std::cout<<d<<" "<<e<<std::endl;
	}
	return 0;
}