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 <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    const int NUM = 60001;
    vector<bool> prime(NUM, true);
    prime[1] = false;
    for (int i = 2; i < NUM; ++i) {
        if (prime[i]) {
            for (int j = i + i; j < NUM; j+=i) {
                prime[j] = false;
            }
        }
    }
    int n, u, d;
    while (cin>>n) {
        for (int i = n-1; i > 1; --i) {
            if (prime[i]) {
                d = i;
                break;
            }
        }
        for (int i = n + 1; i < NUM; ++i) {
            if (prime[i]) {
                u = i;
                break;
            }
        }
        cout << d << " " << u << endl;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cctype>
#include<climits>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<map>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MAX 50100

static bool gosei[MAX];

void a() {
	for (int i = 2; i <= sqrt(MAX); i++)
		if (gosei[i] == false) {
			for (int j = 2, k = 0; (k = i*j) <= MAX; j++)
				gosei[k] = true;
		}
}

int M(int n) {
	for (int i = 1;; i++)
		if (!gosei[n + i])
			return n + i;
}

int m(int n) {
	for (int i = 1;; i++)
		if (!gosei[n - i])
			return n - i;
}

int main() {
	a();
	for (int b; cin >> b;)
		cout << m(b) << " " << M(b) << endl;
	return 0;
}

C++: #include <stdio.h>

int isPrime(int x);

int main(void){
    int n,max,min;
    
    while (scanf("%d",&n)!=EOF){
        for (max=n-1; !isPrime(max); max--);
        for (min=n+1; !isPrime(min); min++);
        printf("%d %d\n", max, min);
    }
    return 0;
}

int isPrime(int x){    
    for (int p=2;p*p<=x; p++){
        if (x%p==0) return 0;
    }
    return 1;
}

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

int main(){
    bool is_prime[1000000];

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

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

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

        if(cin.eof()) break;
        int a,b;
        for(int i=n-1;i>0;i--){
            if(is_prime[i]){
                a=i;
                break;
            }
        }
        for(int i=n+1;i<51000;i++){
            if(is_prime[i]){
                b=i;
                break;
            }
        }

        cout<<a<<' '<<b<<endl;
    }

}

C++: #include <iostream>

using namespace std;

#include<iostream>
#include<algorithm>
using namespace std;

bool p[1000100];

void erato(){
    fill(p, p+1000100, true);
    p[0] = p[1] = false;

    for(int i=0; i < 1000100; i++){
        if(!p[i]) continue;
        for(int j=i+i; j < 1000100; j += i){
            p[j] = false;
        }
    }
}

int main(){
    erato();
    int n;
    while(cin >> n){
        for(int i=n; ; i--)if(p[i] && p[i-2]){cout << i-2 << " " << i << endl;break;}
    }
}

C++: #include<iostream>
using namespace std;
int main(){
  bool num[1000000]={true,true};
  for(int i=2; i<1000; i++)
    if(!num[i])
      for(int j=i*i; j<1000000; j+=i)
	num[j] = true;
  int n;
  while(cin >>n){
    for(int i=n-1;;i--){
      if(!num[i]){cout <<i<<" ";break;}
    }
    for(int i=n+1;;i++){
      if(!num[i]){cout <<i<<endl;break;}
    }
  }
  return 0;
}

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

int main(){
  int table[55000]={};
  for(int i=2; i*i<55000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=55000; j+=i){
        table[j]=1;
      }
    }
  }

  int n;
  while(~scanf("%d",&n)){
    int i;
    for(i=n-1; table[i]; --i);
    cout << i << " ";
    for(i=n+1; table[i]; ++i);
    cout << i << endl;
  }
  return 0;
}

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

bool isprime(int x){
	if(x<=1)return false;
	if(x==2)return true;
	for(int i=2;i<sqrt(x)+1;i++){
		if(x%i==0)return false;
	}
	return true;
}

int main(void){
	int n;
	std::vector<int> v;
	for(int i=2;;i++){
		if(isprime(i)){
			v.push_back(i);
			if(i>50000)break;
		}
	}
	while(cin>>n){
		vector<int>::iterator it=lower_bound(v.begin(),v.end(),n+1);
		cout<<((*(it-1)==n)?(*(it-2)):(*(it-1)))<<" "<<*it<<endl;
	}
	return 0;
}

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

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

int main(){
	int n;
	while(cin >> n){
		for(int i = n - 1; i >= 2; i--){
			if(is_sosu(i)) {
				cout << i << " ";
				break;
			}
		}
		for(int j = n+1;;j++){
			if(is_sosu(j)){
				cout << j << endl;
				break;
			}
		}
	}
	return 0;
}

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

  while(cin >> n){
    if(n < 3 || n > 50000) return 0;
    for(int i=1; i<NUM; i++){
      if(prime[n-i] == 1){
      	  x1 = n-i;
      	  break;
      }
    }
    for(int i=1; i<NUM; i++){
      if(prime[n+i] == 1){
      	  x2 = n+i;
      	  break;
      }
  	}
  	
  	cout << x1 << " " << x2 << endl;

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

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