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 <stdio.h>
#define MAX 60000
int main(void){
 	int i,j;
	int a[MAX+1];
	int n;
	int bn,check;
	while(scanf("%d",&n) != EOF){
		  check = 0;
		  for(i = 1; i <= MAX; i++){
			  a[i] = 0;
		  }
		  for(i = 2; i <= MAX; i++){
			  if(a[i]){continue;}
			  for(j = i; j <= MAX; j += i){
				  if(j == i){a[i] = 0;}
				  else{a[j] = 1;}
			  }
		  }
		  for(i = 2; i <= MAX; i++){
			  if(!a[i]){
				 if(n == i){
					printf("%d ",bn);
					check = 1;
				 }else if(!check){
					bn = i;
				 }else{
					printf("%d\n",i);
					break;
				 }
			  }
		  }
	}
 	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> sosu(60000, 1);

void eratos() {
  for(int i = 2; i < 30000; i++) {
    sosu[2*i] = 0;
  }
  for(int i = 3; i < sqrt(60000); i+=2) {
    if(sosu[i] == 1) {
      for(int j = 1; i*(j+2) < 60000; j++) {
	sosu[i*(j+2)] = 0;
      }
    }
  }
}

int main() {
  eratos();
  int n, i;

  while(cin >> n) {
    
    for(i = n-1; i >= 0; i--){
      if(sosu[i] == 1) {
	cout << i << ' ';
	break;
      }
    }
   
    for(i = n+1; i < 60000; i++){
      if(sosu[i] == 1) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

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

using namespace std;



int main(){
	int in;
	int prime[60001] = {};

	vector<int> p;
	int i, j;
	for (i = 2; i*i < 60000; i++){
		if (prime[i] == 0){
			for (j = 2; i*j <= 60000; j++){
				prime[i*j] = 1;
			}
		}
	}
	for (i = 1; i < 60001; i++){
		if (prime[i] == 0){
			p.push_back(i);
		}
	}



	while (cin >> in){
		for (i = 1; in >= p[i]; i++);
		if (p[i - 1] == in){
			cout << p[i - 2] << " " << p[i] << endl;
		}
		else{
			cout << p[i - 1] << " " << p[i] << endl;
			break;
		}
	}
}

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

vector<int> sieve(int n) {
	vector<int> res(1, 2);
	vector<bool> prime(n, true);
	for(int i = 3; i < n; i += 2) {
		if(prime[i]) {
			res.push_back(i);
			for(int j = i * 3; j < n; j += i * 2)
				prime[j] = false;
		}
	}

	return res;
}

int main() {
	vector<int> prime = sieve(51000);

	for(int n; scanf("%d", &n) == 1;) {
		int idx = lower_bound(prime.begin(), prime.end(), n) - prime.begin();
		if(prime[idx] == n)
			printf("%d %d\n", prime[idx - 1], prime[idx + 1]);
		else
			printf("%d %d\n", prime[idx - 1], prime[idx]);
	}

	return EXIT_SUCCESS;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

// 𝑂(𝑁*log(log 𝑁))
vector<int> eratosthenes(int N)
{
    vector<int> res;
    vector<bool> prime(N + 1, 1);
    prime[0] = prime[1] = false;
    for (int i = 2; i * i <= N; ++i)
    {
        if (prime[i] == true)
        {
            for (int j = 2 * i; j <= N; j += i)
            {
                prime[j] = false;
            }
        }
    }
    for (int i = 0; i <= N; ++i)
    {
        if (prime[i] == true)
            res.push_back(i);
    }
    sort(res.begin(), res.end());
    return res;
}

int m, M, n;

int main()
{
    auto p = eratosthenes(1000010);
    int l = p.size();
    while (cin >> n)
    {
        for (int i = 0; i + 1 < l && n >= p[i]; i++)
        {
            //cout << p[i] << endl;
            if (n == p[i])
            {
                m = p[i - 1], M = p[i + 1];
                break;
            }
            if (n > p[i] && n < p[i + 1])
            {
                m = p[i], M = p[i + 1];
                break;
            }
        }
        cout << m << " " << M << endl;
    }
}

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

int data[51111]={0};
int n;
char c[2];

int main(){

  data[0]=1;
  data[1]=1;

  for(int i=2;i<50001;i++){
    if(data[i]==0){
      for(int j=2;j*i<50001;j++){
        data[i*j]=1;
      }
    }
  }

  while(scanf(" %s",c)!=EOF){

    n=atoi(c);

    for(int i=n-1;i>3;i--){
      if(data[i]!=1){
        cout << i << ' ';
        break;
      }
    }

    for(int i=n+1;i<50001;i++){
      if(data[i]!=1){
        cout << i << endl;
        break;
      }
    }

  }

  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;
        }
    }
    
    }

}

C++: #include<iostream>
using namespace std;
bool notp[51001] = {true,true,false};
void prime(){
	int i,j;
	i=2;
	while(i<=226){
		j=i*i;
		while(j<=51000){
			notp[j] = true;
			j += i;
		}
		i++;
		while(i<=226){
			if(notp[i] == false) break;
			i++;
		}
	}
}

int main(){
	int i,up, low, n;
	prime();/*
	for(i=0;i<100;i++){
		if(notp[i]==false)cout<<i<<endl;
	}*/
	while(cin>>n){
		i=n+1;
		while(true){
			if(notp[i] == false){
				up=i;
				break;
			}
			i++;
		}
		i=n-1;
		while(true){
			if(notp[i] == false){
				low=i;
				break;
			}
			i--;
		}
		cout<<low<<" "<<up<<endl;
	}
	return 0;
}

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

int main(){

  int n,a[1000000]={0};

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

  while(cin >> n){

    for(int i=n-1;i>=2;i--){
      if(a[i]==0){
	cout << i << ' ';
	break;
      }
    }

    for(int i=n+1;i<=1000000;i++){
      if(a[i]==0){
	cout << i << endl;
	break;
      }
    }

  }
}

C++: #include<iostream>
#include<vector>
#define NUM 100000
using namespace std;
int main(){
  int n, prime[NUM];
  vector<int> p;
  for(int i=0; i<NUM; i++) prime[i] = 0;
  prime[0] = 1;
  for(int i=2; i<=NUM/2; i++){
      for(int j=2; i*j <= NUM; j++){
	if(prime[i*j-1] == 0)
	  prime[i*j-1] = 1;
      }
  }
  
  for(int i=0; i<NUM; i++){
    if(prime[i] == 0)
      p.push_back(i+1);
  }

  while(cin >> n){
    if(n < 3 || n > 50000) return 0;
    vector<int>::iterator it = p.begin();
    while(it != p.end()){
      if(n == *it)
	cout << *(it-1) << " " << *(it+1) << endl;
      it++;
    }
  }
  
}

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

int main(int argc, char** argv) {
	int n;
	while (cin >> n) {
		bool data[50000] = { 0 };
		for (int j = 4; j < 50001; j = j + 2) {
			data[j] = 1;
		}
		for (int i = 3; i < 50001; i = i + 2) {
			for (int j = 2 * i; j < 50001; j = j + i) {
				data[j] = 1;
			}
		}

		for (int i = n - 1; i >= 2; --i) {
			if (!data[i]) {
				cout << i;
				break;
			}
		}
		for (int i = n + 1; i < 50001; ++i) {
			if (!data[i]) {
				cout << " " << i << endl;
				break;
			}
		}
	}
}