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>
using namespace std;

const int NUM_MAX = 50000;

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

int getPrimeOverMin(int value){
	if((value & 0x00000001) == 0x00000000){
		++value;
	}
	for(int i=value+2; i<NUM_MAX+1; i+=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}

int getPrimeUnderMax(int value){
	if((value & 0x00000001) == 0x00000000){
		--value;
	}
	for(int i=value-2; i>3; i-=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}


//0044
int main(){
	int n;
	
	while(cin >> n){
		cout << getPrimeUnderMax(n) << " " << getPrimeOverMin(n) << endl;
	}
	return 0;	
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; -i)
#define INF (1 << 30)
#define MOD 1e9 + 7

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define PRIM 50021

bool prim[50022];
int a_prime[500022];

int main(){
	memset(prim, true, sizeof(prim));
	int N;
	while(scanf("%d", &N)) {
		prim[0] = false;
		FOR(i, 1, sqrt(PRIM)) {
			if(prim[i]) {
				for(int j = (i + 1); (i + 1) * j <= PRIM; ++j) {
					prim[(i + 1) * j - 1] = false;
				}
			}
		}
		int cnt = 0;
		rep(i, PRIM) {
			if(prim[i]) a_prime[cnt++] = i + 1;
		}
		rep(i, cnt) {
			if(a_prime[i + 1] >= N) {
				printf("%d ", a_prime[i]);
				break;
			}
		}
		rep(i, cnt) {
			if(a_prime[i] > N) {
				printf("%d\n", a_prime[i]);
				break;
			}
		}
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int sosu[66666];
main(){
  for(int i=2;i<=60000;i++){
    if(sosu[i]==1) continue;
    for(int j=i*2;j<=60000;j+=i){
      sosu[j]=1;
    }
  }
  
  int N;
  while(~scanf("%d",&N))
    {
      int i=N-1;
      while(sosu[i]) i--;
      printf("%d ",i);
      i=N+1;
      while(sosu[i]) i++;
      printf("%d\n",i);
    }
}

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

using namespace std;

int main(){
  int n;

  while(cin>>n){
    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);

      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);
        
        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>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
const int MAX_N = 100010;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    vector<int> prime(MAX_N, 1);
    prime[0] = prime[1] = 0;
    for(int i = 2; i * i < MAX_N; i++)
    {
        for(int j = 2 * i; j < MAX_N; j += i)
        {
            prime[j] = 0;
        }
    }
    while(cin >> n)
    {
        for(int i = n - 1; ; i--)
        {
            if(prime[i] == 0) continue;
            cout << i << " ";
            break;
        }
        for(int i = n + 1; ; i++)
        {
            if(prime[i] == 0) continue;
            cout << i << endl;
            break;
        }
    }
    return 0;
}

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

using namespace std;

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

	bool f1 = false;

	for (int j = n - 1; j > 1; j--) {
		for (int i = 2; i <= sqrt(j); i++) {
			if ((j % i) == 0) {
				f1 = true;
				break;
			}
		}
		if (!f1) {
			cout << j << " ";
			break;
		}
		f1 = false;
	}

	bool f2 = false;

	for (int j = n + 1; true;j++) {
		for (int i = 2; i <= sqrt(j); i++) {
			if ((j % i) == 0) {
				f2 = true;
				break;
			}
		}
		if (!f2) {
			cout << j << endl;
			break;
		}
		f2 = false;
	}

}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
#include<string>
#include<iostream>
#include<queue>
#include<map>
#include<set>
#include<complex>
#include<stack>
#include<cmath>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

const int PS = 1000000;
int prime[PS];
int set_prime(){
	rep(i,PS)prime[i]=1;
	prime[0]=prime[1]=0;
	rep(i,PS){
		if(prime[i]==0)continue;
		for(int j=i*2;j<PS;j+=i)prime[j]=0;
	}
}



int main(){
	set_prime();
	
	int n;
	while(cin>>n){
		for(int i=n-1;i>=0;i--){
			if(prime[i]==1){
				printf("%d ",i);
				break;
			}
		}
		for(int i=n+1;i<PS;i++){
			if(prime[i]==1){
				printf("%d\n",i);
				break;
			}
		}
	}
}

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-1]<<" "<<prime[i]<<endl;
	}
	break;
      }  
    }
  }
  return(0);
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#define p(n) pow(n,2)
using namespace std;
int main(){
  int n,a,b;
  vector<int> v;
  bool f;
  v.push_back(2);
  for(int i=3;i<=50000;i+=2){
    f = true;
    for(int j=0;pow(v[j],2)<=i;j++){
	if(!(i%v[j])){f=false;break;}
    }
    if(f)v.push_back(i);
  }
  v.push_back(50021);
  while(cin>>n){
    if(cin.eof())return 0;
    vector<int>::iterator it = v.begin();
    while(it!=v.end()){
      if(n<*it){
	a=(n==*(it-1))?*(it-2):*(it-1);
	b=*it;
	cout<<a<<" "<<b<<endl;
	break;
      }
      it++;
    }
  }
}

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

int primemax(int m);
int primemin(int m);

int main() {
	int n;
	while (scanf_s("%d",&n) != EOF) {
		cout << primemax(n - 1) << " " << primemin(n + 1) << endl;
	}
}

int primemax(int m) {
	int result = 0;
		while (true) {
		for (int i = m; ; i--) {
			for (int j = sqrt(i)+1;; j--) {
				if ((i%j)==0)break;
				if (j == 2) { result = i; return result; }
			}
		}
	}
}


int primemin(int m) {
	int result = 0;
		while (1) {
			for (int i = m; ; i++) {
				for (int j = sqrt(i)+1; ; j--) {
					if ((i%j)==0)break;
					if (j == 2) { result = i; return result; }
				}
			}
		}
}