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 <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(a)-1;i>=b;i--)
#define chmin(a,b) (a)=min((a),(b));
#define chmax(a,b) (a)=max((a),(b));
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define printV(v) cerr<<(#v)<<":";for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;
#define printVS(vs) cerr<<(#vs)<<":"<<endl;for(auto(s):(vs)){cerr<<(s)<< endl;}
#define printVV(vv) cerr<<(#vv)<<":"<<endl;for(auto(v):(vv)){for(auto(x):(v)){cerr<<" "<<(x);}cerr<<endl;}
#define printP(p) cerr<<(#p)<<(p).first<<" "<<(p).second<<endl;
#define printVP(vp) cerr<<(#vp)<<":"<<endl;for(auto(p):(vp)){cerr<<(p).first<<" "<<(p).second<<endl;}

inline void output(){ cerr << endl; }
template<typename First, typename... Rest>
inline void output(const First& first, const Rest&... rest) {
    cerr << first << " "; output(rest...);
}

using ll = long long;
using Pii = pair<int, int>;
using TUPLE = tuple<int, int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
const int inf = 1ll << 60;
const int mod = 1e9 + 7;
using Graph = vector<vector<int>>;

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int N = 100000;
  vector<int> prime;
  vector<bool> alive(N, true);
  alive[0] = alive[1] = false;
  rep2(i, 2, N) {
      if (alive[i]) {
          prime.emplace_back(i);
          for (int j = 2 * i; j < N; j += i) {
              alive[j] = false;
          }
      }
  }

  int n;
  while (cin >> n) {
    auto itr = upper_bound(all(prime), n);;
    int b = *itr;
    itr--;
    if (*itr == n) itr--;
    int a = *itr;
    cout << a << " " << b << endl;
  }
}

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

const int MAX = 100000;

int main ()
{
    vector<int> num(MAX + 1, 1);
    num[0] = num[1] = -1;
    for (int i = 2; i <= MAX / 2; i++) {
        for (int j = 2; i * j <= MAX; j++) {
            num[i*j] = -1;
        }
    }

    vector<int> prim;
    for (int i = 0; i < num.size(); i++) {
        if (num[i] == 1) {
            prim.push_back(i);
        }
        num[i] = prim.size() - 1;
    }

    int n;
    while (cin >> n) {
        cout << prim[num[n]-1] << " " << prim[num[n]+1] << endl;
    }

    return 0;
}

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

int main(){
	bool dt[51001];
	int count=0;
	for(int i=3;i<51001;i++){
		for(int j=3;j<250;j++){
			if(i%j==0){count++;}
		}
		if(i<250){if(count==1){dt[i]=true;}else{dt[i]=false;}}
		else{if(count==0){dt[i]=true;}else{dt[i]=false;}}
		count=0;
	}
	int n=0;
	while(cin>>n){
		int i=0;
		int ansf=0,ansl=0;
		for(i=1;i<n;i++){
			if(dt[i]==true){ansf=i;}
		}
		i++;
		while(i>0){
			if(dt[i]==true){ansl=i;i=-10;}
			i++;
		}
		cout<<ansf<<" "<<ansl<<endl;
	}
	return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 1000000

using namespace std;

int prime[MAX];

int main()
{
	prime[0] = prime[1] = 0;

	REP(i,2,MAX)
	{
		prime[i] = 1;
	}

	REP(i,2,MAX)
	{
		if(prime[i])
		{
			for(int j = i*2;j < MAX;j += i)
			{
				prime[j] = 0;
			}
		}
	}

	int n;

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


	return 0;
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
int main(void){
  int i,no,input;
  int prime[500];
  int ptr=0,c=0;
  int flag=0;
  int last;
  
  while(cin>>input){
    flag=ptr=c=0;
    prime[ptr++]=2;
    prime[ptr++]=3;
    for(no=5;;no+=2){
      if(flag==2){break;}
      if(input+1<=no){flag=1;c++;}
      if(c==1){if(input==prime[ptr-1])last =ptr-2;else last=ptr-1;}
      for(i=1;i<ptr;i++){
	if(no%prime[i]==0)break;
      }
      if(ptr==i){
	prime[ptr++]=no;
	if(flag==1){flag=2;}
      }
    }
    
    printf("%d %d\n",prime[last],prime[ptr-1]);
  }
    return 0;
}

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

int main(void)
{
   int prime[50000];
   prime[0] = 2;
   prime[1] = 3;
   int ptr = 2;
   for(int num = 5; num <= 50100; num++){
       bool f = false;
       for(int i=0;i<ptr;i++){
           if(prime[i]*prime[i]>num){
               break;
           }
           if(num%prime[i]==0){
               f=true;
               break;
           }
       }
       if(!f){
           prime[ptr++] = num;
       }
   }
   int n;
   while(cin>>n){
       int j=0;
       while(prime[j]<=n){
           j++;
       }
       if(prime[j-1]==n){
           cout<<prime[j-2]<<" "<<prime[j];//printf("%d %d",prime[j-2],prime[j]);
       }else{
           cout<<prime[j-1]<<" "<<prime[j];//printf("%d %d",prime[j-1],prime[j]);
       }
       cout<<endl;
   }
   return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{ 
  const int END = -1;
  const int NUM = 50000;
  int num;
  int i,index,index2,index3;
  
  cin >> num;

  vector<int> eratos(NUM);

  for(i = 0;i < NUM - 1 ; i++)
    eratos[i] = i+2;
  eratos[i] = END;
 
  while(!cin.eof()){
    i = 0;
    index3 = 0;
  while(eratos[i]!=END)
    {
      if(eratos[i]!=0)
        {
          index = i + 1;
          index3 = i + 1;
          while(eratos[index]!=END)
            {
              if(eratos[index]%eratos[i] != 0)
                {
                  eratos[index3] = eratos[index];
                  index3++;
                }
              index++;
            }
          eratos[index3] = END;
        }
      i++;
    }
 
  for(i = 0; i < index3; i++)
    {
      if(eratos[i]==num)
        {
          cout << eratos[i-1] << " " << eratos[i+1] << endl;
          break;
        }
      else if(eratos[i] > num)
        {
          cout << eratos[i-2] << " " << eratos[i+1] << endl;
          break;
        }
    }
    cin >> num;
  }
  return 0;
}