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 <string>
#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
 
using namespace std;

const int SIZE = 50100;
bool isP[SIZE];
  
int main(){
	fill(isP, isP+SIZE+1, true);
	for(int i = 2; i <= SIZE; i++){
		if(isP[i]){
			for(int j = i*2; j <= SIZE; j += i){
				isP[j] = false;
			}
		}
	}

	int n;

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

	return 0;
}

C++: #include <iostream>
using namespace std;
 
int main(){
  bool is_prime[50005];
 
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<50005;i++){
    is_prime[i] = true;
  }
 
  for(int i=2;i*i<50005;i++){
    if(is_prime[i]){
      for(int j=i*i;j<50005;j=j+i){
        is_prime[j] = false;
      }
    }
  }
 
  while(true){
    int n;
    cin >> n;
 
    if(cin.eof())
        break;
 
    int high = n;
    int low = n;
 
    while(1){
      high = high+1;
      if(is_prime[high]){
        break;
      }
    }
 
    while(1){
      low = low-1;
      if(is_prime[low]){
        break;
      }
    }
 
    cout << low << " " << high << endl;
  }
 
  return 0;
}

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

const int MAX_NUM = 500000;
bool prime_number[MAX_NUM];
 
void isPrime() {
    fill(prime_number, prime_number + MAX_NUM, true);
    prime_number[0] = prime_number[1] = false;
 
    for(int i = 2; i < MAX_NUM; i++) {
        if(prime_number[i])
        for(int j = 2; i*j < MAX_NUM; j++) {
            prime_number[i*j] = false;
        }
    }
}
int main(void){
  int n;
  isPrime();
  while(cin>>n){
    int i;

    for(i = (!prime_number[n]?n:n-1) ; !prime_number[i] ; i --);
    cout<<i<<" ";
    for(i = (!prime_number[n]?n:n+1) ; !prime_number[i] ; i ++);
    cout<<i<<endl;
  }
}

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


int main(){
	bool prime[60000];
	for(int i=0;i<60000;i++){
		prime[i]=1;
	}
	prime[0]=prime[1]=0;
	for(int i=0;i*i<60000;i++){
		if(prime[i]==1){
			for(int j=i*2;j<60000;j+=i){
				prime[j]=0;
			}
		}
	}
	int n;
	while(cin>>n){
		int i;
		for(i=1;prime[n-i]==0;i--);
		cout<<n-i<<" ";
		for(i=1;prime[n+i]==0;i++);
		cout<<n+i<<endl;
	}
}

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

bool ba[m+1] = { true };
int cp(int x) {
	int co = 0;
	for (int i = 0; i < m+1; i++) {
		ba[i] = { true };
	}
	for (int i = 2; i*i <= 52000; i++) {
		if (ba[i]) {
			for (int j = i*i; j <= 52000; j += i) {
				ba[j] = { false };
			}
		}
	}
	for (int i = 2; i <x; i++) {
		if (ba[i]) {
			co = i;
		}
	}
	return co;
}

int main() {
	int n;
	while (cin >> n) {
		int a = cp(n);
		while (ba[n + 1] == false) {
			n++;
		}
		cout << a << ' ' << n + 1 << endl;
	}
	return 0;
}

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

#define MAX_N 50010

int prime[MAX_N];
bool is_prime[MAX_N + 1];


void prime_generate(){
	int p = 0;
	for(int i = 0; i <= MAX_N; i++) is_prime[i] = true;

	is_prime[0] = is_prime[1] = false;

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

void solve(int n){
	for(int i = 0; i < MAX_N; i++){
		if(prime[i] == n){
			cout << prime[i-1] << " " << prime[i+1] << endl;;
			break;
		}
		else if(prime[i] > n){
			cout << prime[i-1] << " " << prime[i] << endl;
			break;
		}
		else continue;
	}
}

int main(){
	prime_generate();

	int n;
	while(cin >> n){
		solve(n);
	}
}

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

int main(){
  bool a[1000000];

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

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

  int min,max;

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

    if(cin.eof()){
      break;
    }

    for(int i=3;i<m;i++){
      if(a[i]){
        max=i;
      }
    }
    for(int i=m+1;i<=50000;i++){
      if(a[i]){
        min=i;
        break;
      }
    }

    cout<<max<<' '<<min<<endl;

  }

  return 0;
}

C++: #include<cstdio>
#include<iostream>
using namespace std;
int main(){
    int check[50001] = {0};

    int flg = 0;
    for(int i = 3;i <= 50000; i+=2){
        flg = 1;
        for(int j = 2;j*j <= i; j++){
            if(i%j == 0){
                flg = 0;
                break;
            }
        }
        if(flg == 1)check[i] = 1;
    }
    check[2] = 1;

    int n;
    while(scanf("%d",&n) != EOF){
        for(int i = n-1;i > 0;i--){
            if(check[i] == 1){
                printf("%d ",i);
                break;
            }
        }
        for(int i = n+1;i <= 50000;i++){
            if(check[i] == 1){
                printf("%d\n",i);
                break;
            }
        }
    }
    return 0;
}

C++: #include<iostream>

#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) for(int i=0;i<a;i++)


using namespace std;



int main(){
	bool prime[1000001];
	rep(i, 1000001){
		prime[i] = true;
	}
	prime[0] = prime[1] = false;

	loop(i, 2, 1001){
		if (prime[i]){
			for (int j = i * 2; j < 1000001; j += i){
				prime[j] = false;
			}
		}
	}



	int ord;
	while (cin >> ord){
		int small, big;
		loop(i, ord+1, 1000001){
			if (prime[i]){
				big = i;
				break;
			}
		}
		for (int i = ord-1; i > 0; i--){
			if (prime[i]){
				small = i;
				break;
			}
		}

		cout << small << " " << big << endl;
	}

}

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

int main(){
    bool isPrime[n_size];
    isPrime[0] = false;
    isPrime[1] = false;

    for (unsigned i = 2; i < n_size; i++)
        isPrime[i] = true;

    for (unsigned i = 2; i * i < n_size; i++){
        if (isPrime[i]){
            for (unsigned j = (i * i); j < n_size; j += i)
                isPrime[j] = false;
        }
    }

    unsigned n;
    while(cin >> n){
        unsigned a = n-1;
        unsigned b = n+1;
        while(!isPrime[a])
            a--;
        while(!isPrime[b])
            b++;
        cout << a << " " << b << endl;
    }
    
    return 0;
}

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

bool IsPrime(int num){
    if(num < 2){
        return false;
    }else if(num == 2){
        return true;
    }else{
        for(int i = 2; i*i <= num;i++){
            if(num % i == 0){
                return false;
            }
        }
        return true;
    }
}

int main() {
   
    std::string str;
    int num = 0;
    while(std::cin>>num){
        for(int i = num-1; 2 < i;i--){
        if(IsPrime(i) == true){
            printf("%d ",i);
            break;
        }
    }
    for(int k = num+1;k < 50022; k++){
        if(IsPrime(k) == true){
            printf("%d\n",k);
            break;
        }
    }
    
    }


}