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 <vector>

using namespace std;

int main(){
  const int size=50022;
  bool composite[size]={0};
  composite[0]=composite[1]=true;
  for(int i=0;i<size;i++){
    if(!composite[i]){
      for(int j=i*2;j<size;j+=i){
        composite[j]=true;
      }
    }
  }
  vector<int> array;
  int n;
  while(cin>>n){
    array.push_back(n);
  }

  for(auto number:array){
    int i=0;
    for(i=number-1;composite[i];i--);
    cout<<i<<" ";
    for(i=number+1;composite[i];i++);
    cout<<i<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lowb lower_bound
#define upb upper_bound
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }
    return true;
}

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

    int n;
    while(cin >> n) {
        int t = n;

        while(--t) {
            if(IsPrime(t)) {
                cout << t << " ";
                break;
            }
        }

        t = n;
        while(++t) {
            if(IsPrime(t)) {
                cout << t << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int main(){
  int n;
  cin>>n;

  //while(1){
    int ans_ma;
    int ma_n = n + 1;
    int c_ma = 0;

    if(ma_n % 2 == 0){
        ++ma_n;
    }

    for(int i = ma_n; ;i = i + 2){
      int q = sqrt(i);

      if(q < 3){
        ans_ma = q;
        break;
      }
        
      else{
        c_ma = 1;
        for(int j = 3;j <= q;j = j + 2){
          if(i % j == 0){
            c_ma = 0;
            break;
          }
        }
        if(c_ma == 1){
          ans_ma = i;
          break;
        }
      }
    }

    int ans_mi;
    int mi_n = n - 1;
    int c_mi = 0;

    if(mi_n == 2){
      ans_mi = 2;
    }
    else{
      if(mi_n % 2 == 0){
        --mi_n;
      }
      for(int i = mi_n;i > 3;i = i - 2){
        int q = sqrt(i);

        if(q < 3){
          ans_mi = q;
          break;
        }
        else{
          c_mi = 1;
          for(int j = 3;j <= q;j = j + 2){
            if(i % j == 0){
              c_mi = 0;
              break;
            }
          }
          if(c_mi == 1){
            ans_mi = i;
            break;
          }
        }
      }
    }
    cout<<ans_mi<<" "<<ans_ma<<endl;
  //}
  return 0;
}

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

int main() {
	bool prime[55001] = { false };
	for (int i = 2; i <= sqrt(55000); i++) {
		if (!prime[i]) {
			for (int j = 2; i*j <= 55000; j++) {
				prime[i*j] = true;
			}
		}
	}
	int n;
	while (cin >> n) {
		for (int i = n-1;; i--) {
			if (!prime[i]) {
				cout << i << " ";
				break;
			}
		}
		for (int i = n+1;; i++) {
			if (!prime[i]) {
				cout << i << endl;
				break;
				}
			}
		}
}

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

using namespace std;

bool prime_check(int N)
{
	if (N == 1) { return false; }

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

	return true;
}

int main()
{
	int N;

	while (cin >> N)
	{
		for (int i = (N - 1); i > 1; i--)
		{
			if (prime_check(i) == true)
			{
				cout << i << ' '; goto Exit1;
			}
		}

	Exit1:;

		for (int i = (N + 1); i < 50022; i++)
		{
			if (prime_check(i) == true)
			{
				cout << i << endl; goto Exit2;
			}
		}

	Exit2:;
	}

	return 0;
}

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

int main() {
	int n;
	int cnt = 0;
	while(cin >> n) {
		cnt++;
	}
	if(cnt > 1000)
		exit(1);
}

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

using namespace std;

int main()
{
  bitset<50001> is_prime;
  is_prime.set();
  is_prime[0] = false, is_prime[1] = false;
  for (int i = 2; i * i <= 50000; i++) {
    for (int j = i + i; j  <= 50000; j += i) {
      is_prime[j] = false;
    }
  }

  int N;
  while (scanf("%d ", &N) == 1) {
    int d_m, u_m;
    for (int i = N - 1;; i--) {
      if (is_prime[i]) {
	d_m = i;
	break;
      }
    }
    for (int i = N + 1;; i++) {
      if (is_prime[i]) {
	u_m = i;
	break;
      }
    }
    printf("%d %d\n", d_m, u_m);
  }
  return 0;
}

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

int main()
{
   int n;
   int prime[60000] = {1,1};
   vector<int> r1,r2;
   int count=0;
   for (int i=2; i<=244; i++)
   {
       if (prime[i] == 0)
       {
	   for (int j=i*2; j<60000; j+=i)
	   {
	       prime[j] = 1;
	   }
       }
   }
   while (scanf("%d",&n) != EOF)
   {
       int previous,forward;
       for (int i=n-1; i>0; i--)
       {
	   if (prime[i]==0)
	   {
	       previous = i;
	       break;
	   }
       }
       for (int i=n+1; i<60000; i++)
       {
	   if (prime[i]==0)
	   {
	       forward = i;
	       break;
	   }
       }
       r1.push_back(previous);
       r2.push_back(forward);
   }
   for (int i=0; i<r1.size(); i++)
   {
       cout << r1[i] << " " << r2[i] << endl;
   }
   return 0;
}

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

using namespace std;

int main(void){
  int prime[50000];
  int prime_f[51001];
  int k;
  int n;
  int i,j;
  int n_size;

  while(cin>>n){
    k=0;
    memset(prime_f,0,sizeof(prime_f));
    prime_f[0]=prime_f[1]=1;
    for(i=2;i<51000;i++){
      if(!prime_f[i]){
	k++;
	prime[k]=i;
	for(j=2*i;j<50000;j+=i){
	  prime_f[j]=1;
	}
      }
    }

    for(i=0;i<k;i++){
      if(prime[i]>=n){
	if(prime[i]=n){
	  cout<<prime[i-1]<<" "<<prime[i+1]<<endl;
	}else{
	  cout<<prime[i]<<" "<<prime[i+1]<<endl;
	}
	break;
      }  
    }
  }
  return(0);
}