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;
#define MAX 50001

bool prime[MAX];
void calcPrime(){
	for(int i = 2; i < MAX; i++) prime[i] = true;
	for(int i = 2; i < MAX; i++){
		if( prime[i] ){
			for(int j = i+i; j <= MAX; j += i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	int n;
	calcPrime();
	while( cin >> n ){
		int under = -1, over = -1;
		for(int d = n-1, u = n+1; 0 < d || u < MAX; ){
			if( 2 < d ) d--;
			if( u < MAX ) u++;
			if( under != -1 && over != -1 ) break;
			if( prime[d] ) under = d;
			if( prime[u] ) over = u;
		}
		cout << under << " " << over << endl;
	}
}

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

int main(){
  bool is_prime[52000];
  is_prime[0]=false;is_prime[1]=false;
  for(int i=2;i<52000;i++)is_prime[i]=true;
  for(int i=2;i<=sqrt(51999);i++){
    if(is_prime[i]){
      for(int j=2;i*j<=51999;j++)is_prime[i*j]=false;
    }
  }

  int primes[52000];int index=0;
  for(int i=2;i<=51999;i++)
    if(is_prime[i]){
      primes[index]=i;
      index++;
    }

  int n;index=0;
  while(cin>>n){
    while(primes[index]!=n){
      index++;
    }
    cout<<primes[index-1]<<' '<<primes[index+1]<<endl;
  }
}

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

#include<vector>

#define INF 999999
using namespace std;
bool prime[55000]={0};
int main(){
    prime[1]=1;
    for(int i=2;i*i<50000;i++){
        if(prime[i]==0){
            for(int j=i;j<=50000;j+=i){
                if(prime[j]==0){
                    prime[j]=1;
                }
            }
            prime[i]=0;
        }
    }
    int N;
    while(~scanf("%d",&N)){
        for(int i=N-1;;i--){
            if(prime[i]==0){cout<<i<<" ";break;}
        }
        for(int i=N+1;;i++){
            if(prime[i]==0){cout<<i<<endl;break;}
        }
    }
    return 0;
}

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

#define iota(i,n,b,s) for(int i=int(b);i!=int((b)+(s)*(n));i+=(s))
#define range(i,n,m) iota(i,(((n)>(m))?((n)-(m)+1):((m)-(n)+1)),(n),((n)>(m)?-1:1))
#define rep(i,n) iota(i,(n),0,1)
#define loop for(;;)

#define INF (1e9)
#define EPS (1e-9)
#define cons(a,b) (make_pair(a,b))
#define car(a) (a.first)
#define cdr(a) (a.second)
#define cadr(a) (car(cdr(a)))
#define cddr(a) (cdr(cdr(a)))
#define all(a) a.begin(), a.end()
#define trace(var) cerr<<">>> "<<#var<<" = "<<var<<endl;

typedef long long Integer;
typedef double Real;

template<class S, class T>
ostream& operator<<(ostream& os, pair<S,T> p) {
  os << '(' << car(p) << ", " << cdr(p) << ')';
  return os;
}

template<class T>
ostream& operator<<(ostream& os, vector<T> v) {
  os << v[0];
  for (int i=1, len=v.size(); i<len; ++i) os << ' ' << v[i];
  return os;
}

int dx[] = { -1, 0, 1, 0 };
int dy[] = {  0, -1, 0, 1 };

bool* PrimeSieve(int n) {
  bool*s = new bool[n];
  for (int i = 0; i < n; ++i) s[i] = true;
  s[0] = s[1] = false;
  for (int i = 2; i < n; ++i)
    if (s[i]) for (int j = 2 * i; j < n; j += i) s[j] = false;
  return s;
}

int main() {

  const int N = 50000;
  auto isprime = PrimeSieve(N);

  loop {
    int n; cin >> n;
    if (!cin) break;
    int a,b;
    for (int m = n-1; m > 0; --m) {
      if (isprime[m]) {
        a = m;
        break;
      }
    }
    for (int m = n+1; m < N; ++m) {
      if (isprime[m]) {
        b = m;
        break;
      }
    }
    cout << a << ' ' << b << endl;
  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
const int INF = 1 << 20;

typedef long long ll;

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


int main(){
  int n,m;

  while(cin >> n){
    int a = n-1;
    while(1){
      bool f = Sosuu(a);
      if(f)
	break;
      a--;
      
    }
    int b = n+1;
    while(1){
      bool f = Sosuu(b);
      if(f)
	break;
      b++;
    }
    cout << a << " " << b << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int main(){
	vector<int>prime;
	for(int i=2;i<=100000;i++){
		bool f=1;
		for(int j=2;j*j<=i;j++)if(i%j==0)f=0;
		if(f)prime.push_back(i);
	}
	int n;
	while(cin>>n){
	int a=0,b=0;
	for(int i=0;;i++){
		if(prime[i]>n){b=prime[i];break;}
		else if(prime[i]==n){b=prime[i+1];break;}
		a=max(prime[i],a);
	}
	cout<<a<<" "<<b<<endl;
	}
	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> primenum;
  primenum.push_back(2);
  for(int i=3;i<=60000;i+=2){
    int k=0;
    for(int j=3;j<=sqrt(i);j+=2){
      if(i%j==0){
	k=1;
	break;
      }
    }
    if(k==0)
      primenum.push_back(i);
  }
  int num;
  while(cin>>num){
    for(int i=0;i<primenum.size();i++){
      if(primenum[i]==num){
	cout<<primenum[i-1]<<" "<<primenum[i+1]<<endl;
	break;
      }else if(primenum[i]>num){
	cout<<primenum[i-1]<<" ";
	cout<<primenum[i]<<endl;
	break;
      }
    }
  }
  return 0;
}

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

/** Problem0044 : Prime Number II **/
#define MAX 51000
int main()
{
	bool prime[MAX];
	int  input;
	
	for (int i=0; i<MAX; i++)
		prime[i] = true;
	
	prime[0] = false; prime[1] = false;
	
	for (int i=2; i<MAX; i++) {
		if (prime[i]) {
			for (int j=2; i*j<MAX; j++) {
				prime[i*j] = false;
			}
		}
	}
	
	while (cin >> input) {
		for (int i=input-1; i>1; i--) {
			if (prime[i]) {
				cout << i << " ";
				break;
			}
		}
		
		for (int i=input+1; i<50000; i++) {
			if (prime[i]) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

int main(){
  bool  prime[100000];
  for(int i=0;i<100000;i++){
    prime[i]=true;
  }
  prime[0]=prime[1]=false;
  for(int i=2;i<=1000;i++){
    for(int j=i*2;j<100000;j+=i){
      prime[j]=false;
    }
  }
  int n;
  int cnt1,cnt2;
  while(cin>>n){
    for(int i=0;i<n;i++){
      if(prime[i])cnt1=i;
    }
    for(int i=n+1;;i++){
      if(prime[i]){
	cnt2=i;
	break;
      }
    }
    cout<<cnt1<<" "<<cnt2<<endl;
  }
  return 0;
}

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

int main(){
  bool is_prime[50001];

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

  for(int i=2;i*i<50001;i++){
    if(is_prime[i]){
      for(int j=i*i;j<50001;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;
}