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

using namespace std;

bool era[50030];
int main()
{
	for(int i=2;i<300;i++)if(!era[i])for(int j=i*i;j<50030;j+=i)era[j]=true;
	vector<int> p;
	for(int i=2;i<50030;i++)if(!era[i])p.push_back(i);

	int n;
	while(~scanf("%d",&n)){
		vector<int>::iterator it_l,it_u;
		it_l=it_u=upper_bound(p.begin(),p.end(),n);
		it_l-=era[n]?1:2;
		printf("%d %d\n",*it_l,*it_u);
	}

	return 0;
}

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

int a[100000];

void sosuu() {
	a[0] = 2;
	int k, z = 1;
	for (int i = 3; i<100000; i++) {
		k = 0;
		for (int j = 0; a[j] <= sqrt(i); j++) {
			if (i%a[j] == 0) {
				k++;
				break;
			}
		}
		if (k == 0) {
			a[z] = i;
			z++;
		}
	}
	return;
}

int nibun(int n, int s, int e){
	if (s >= e) return s;
	if(a[(s + e)/2] < n){
		if(a[(s+e)/2 + 1]>n ){
			return (s + e) / 2;
		}
		return nibun(n, (s + e) / 2 + 1, e);
	}
	else if(a[(s + e) / 2] > n){
		return nibun(n, s, (s + e) / 2 - 1);
	}
	else return (s + e) / 2;
}


int main(){
	sosuu();
	int n, k;
	while(cin >> n){
		int ret = nibun(n, 0, 10000);
		if(n == a[ret]){
			cout << a[ret - 1] << " " << a[ret + 1] << endl;
		}

		else cout << a[ret] << " " << a[ret + 1] << endl;
	}
	return 0;
}

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

const int MAX_S = 1000000;
bool p[MAX_S];


void prime() {
  fill(p, p+MAX_S, true);
  p[0] = p[1] = false;
  for(int i = 2; i < MAX_S; i++) {
    if(p[i]) {
      for(int j = 2; i*j < MAX_S; j++) {
        p[i*j] = false;
      }
    }
  }
}

int main() {
  int x, y;
  prime();
  while(cin >> x) {
    int n;
    bool b = false;
    for(int i = 2; i < MAX_S; i++) {
      if(b && x != n) {
        cout << n << endl;
        b = false;
      }
      if(x == i) {
        cout << n << ' ';
        b = true;
      }
      if(p[i]) n = i;
    }
  }
}

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


vector<int> prime;


void sieve(){
	prime.resize(100000);
	iota(prime.begin(), prime.end(), 2);
	for (int i = 0;prime[i]*prime[i] < 100000;i++){
		prime.erase(remove_if(prime.begin() + (i + 1), prime.end(), [=](int v){ return (v%prime[i] == 0); }), prime.end());
	}
}


int main(){
	int n;
	sieve();
	while (cin >> n){
		cout << *(upper_bound(prime.begin(), prime.end(), n) - 2) << ' ' << *(upper_bound(prime.begin(), prime.end(), n)) << endl;
	}
	return 0;
}

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

int main(void){
bool isprime[N];
for(int i=0;i<N;i++)
	isprime[i]=true;
isprime[0]=isprime[1]=false;
for(int i=2;i<N;i++)
	if(isprime[i])
		for(int j=i*2;j<N;j+=i)
			isprime[j]=false;

	while(true){
		int n;
		cin >> n;
		if(cin.eof())
			break;
		int min=0,max=0;
		for(int i=n-1;i>=2;i--){
			min=i;
			if(isprime[i])
				break;
		}
		for(int i=n+1;i<N;i++){
			max=i;
			if(isprime[i])
				break;
		}
		cout << min << ' ' << max << endl;
	}
	return 0;
}

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;p[j];j--){}
    cout << j << ' ';
    for(j=i+1;p[j];j++){}
    cout << j << 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;}
	}
	G[2]=true;
	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 <algorithm>
#include <vector>
using namespace std;

const int MAXP = 50004;

bool isP[MAXP];
vector<int> Pv;

int init() {
  fill(isP, isP+MAXP, true);
  isP[0] = isP[1] = false;
  for(int i = 2; i < MAXP; ++i) {
    if(!isP[i]) continue;
    Pv.push_back(i);
    for(int j = i*2; j < MAXP; j += i) isP[j] = false;
  }
  return Pv.size();
}

int main() {
  int n;
  init();
  while(cin >> n) {
    int p = lower_bound(Pv.begin(), Pv.end(), n) - Pv.begin();
    int q = p+1;
    if(Pv[p] == n) --p;
    cout << Pv[p] << " " << Pv[q] << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string.h>

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

void calc()
{
	memset(IsPrime, 1, sizeof(bool) * 55000);
	for(int i = 2; i < 55000; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < 55000; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	calc();
	int n;
	while(cin >> n)
	{
		int pos = 0;
		while(Prime[pos] < n)
		{
			pos++;
		}
		cout << Prime[pos - 1] << " " << Prime[pos + 1] << endl;
	}
}

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

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

using namespace std;

typedef long long ll;
typedef pair<int,int> P;


int main(){
	char buf[32];
	vector<int> nums;
	map<int,int> freq;
	int* dp = new int[60001];

	fill((int*)dp,(int*)dp+60001,1);

	dp[0]=0;
	dp[1]=0;

	for(int i=2;i<=60000;i++){
		if(dp[i]){
			for(int j=i+i;j<=60000;j+=i){
				dp[j]=0;
			}
		}
	}

	int num;
	while(~scanf("%d",&num)){
		for(int i=num-1;i>=0;i--){
			if(dp[i]){
				cout << i << " ";
				break;
			}
		}

		for(int i=num+1;i<=60000;i++){
			if(dp[i]){
				cout << i << endl;
				break;
			}
		}
	}
}

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

int n, m, k;

bool prime(int a) {
    if (a > 2 && a % 2 == 0)
        return false;

    for (int i = 3; i * i <= a; i += 2)
        if (a % i == 0)
            return false;

    return true;
}

int main()
{
    while (cin >> n) {
        m = n - 1;
        k = n + 1;

        while (!prime(m))
            m--;

        while (!prime(k))
            k++;

        cout << m << " " << k << endl;
    }
}

C++: #include <cstdio>
#include <iostream>
#define M 50200

using namespace std;

int main() {

	int n, min, max, s[M];
	bool x[M];

	for(int i=2; i<=M; i++) {
		x[i]=false;
	}
	for(int i=2; i<224; i++) {
		if(x[i])
			continue;
		for(int j=i*2; j<M; j+=i) {
			if(!x[j])
				x[j]=true;
		}
	}
	for(int i=2; i<M; i++) {
		s[i]=0;
	}

	s[2]=2;
	for(int i=3; i<M; i+=2) {
		if(!x[i])
			s[i]=i;
	}

	while(scanf("%d", &n)!=EOF) {
		max=0;
		for(int i=3; ; i+=2) {
			if(s[i]>n) {
				max=s[i];
				for(int j=i; j!=0; j--) {
					if(s[j]<n&&s[j]!=0) {
						min=s[j];
						break;
					}
				}
			}
			if(max!=0)
				break;
		}
		cout << min << " " << max << endl;
	}
	

	return 0;

}