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

bool prime[60000];

void func(){
    fill(prime,prime+60000,1);
    prime[0] = prime[1] = 0;
    for(int i=2;i*i<60000;i++){
        if(prime[i]){
            for(int j=i*2;j<60000;j+=i){
                prime[j]=0;
            }
        }
    }
}

int main() {
    func();
    int n,i=0;
    while(cin>>n){
        for(i=n-1;prime[i]!=1;i--){}
        cout << i << ' ';
        for(i=n+1;prime[i]!=1;i++){}
        cout << i << endl;
    }
	return 0;
}

C++: #include <iostream>
#include <cmath>
bool prime[51001];
using namespace std;
int main(){
	int i,j,n;

	for (i = 3; i <= 51000; i += 2){
		prime[i] = true;
	}
	prime[2] = true;

	for (i = 3; i <= (int)sqrt(51000.); i += 2){
		if (prime[i] == 1){
			for (j = 3; j <= 51000 / i; j += 2){
				prime[i * j] = false;
			}
		}
	}
	while(cin >> n && n){
		for(i=n-1;i>1;i--){
			if(prime[i]){
				cout << i << " ";
				break;
			}
		}
		for(i=n+1;i<51001;i++){
			if(prime[i]){
			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 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);

  for (int n; cin >> n, cin;) {
    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 <iostream>
#include <cstring>
using namespace std;

bool primeFlg[1000000];

void makePrime(){
  memset(primeFlg, true, sizeof(primeFlg));
  primeFlg[0] = primeFlg[1] = false;

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

int main(){
  int n;

  makePrime();

  while(cin >> n){
    for(int i = n - 1; ; i--){
      if(primeFlg[i]){
        cout << i << " ";
        break;
      }
    }

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

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

int main() {

int a[50010];
a[0]=0;
a[1]=0;
a[2]=1;
a[3]=1;
a[5]=1;
for(int kk=2;kk<25001;kk++){
	a[2*kk]==0;
}
for(int k=3;k<25000;k++){
	int n,q=1;
	n=sqrt(2*k+1);
	for(int j=1;j<=n/2;j++){
	if(	(2*k+1)%(2*j+1)==0){
		q=0;
	}
	}
a[2*k+1]=q;
}
int p;
while(cin>>p){
	int l=1,m=1;
	while(a[p+l]==0){
		l=l+1;
	}
	while(a[p-m]==0){
		m=m+1;
	}
	cout<<p-m<<" "<<p+l<<endl;
}

	return 0;
}

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

using namespace std;
bool IsPrime[60000];
vector<int> Prime;

void PrimeCalc()
{
	for(int i = 0; i < 60000; ++i)
	{
		IsPrime[i] = true;
	}
	IsPrime[0] = IsPrime[1] = false;
	for(int i = 2; i < 60000; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < 60000; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	PrimeCalc();
	int n;
	while(~scanf("%d", &n))
	{
		int count = 0;
		while(n > Prime[count])
		{
			++count;
		}
		cout << Prime[count - 1] << " ";
		if(IsPrime[Prime[count]])
		{
			++count;
		}
		cout << Prime[count] << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int prime[MAX];

void is_prime(){
  for(int i = 0 ; i < MAX ; i++) prime[i] = 1;
  
  prime[0] = prime[1] = 0;
  for(int i = 2 ; i*i < MAX ; i++){
    if(prime[i] = 1){
      for(int j = 2*i ; j < MAX ; j += i){
        prime[j] = 0;
      }
    }
  }
}

int main(void){
  int n;

  is_prime();

  while(cin >> n){
    for(int i = n - 1 ; prime[i] == 0 ; i--);
    cout << i << ' ';

    for(int j = n + 1 ; prime[j] == 0 ; j++);
    cout << j << endl;
  }

  return 0;
}

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

int main(){
  bool is_prime[100000];

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

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

    while(1){
      low--;
      if(is_prime[low]){
        break;
      }
    }

    cout << low << " " << high << endl;
  }

  return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;

int const N = 1000010;
int ans[N];

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

int main(int argc, char ** argv) {
    int n;
    while (~scanf("%d", &n)){
        int lo = n - 1, hi = n + 1;
        while (!isprime(lo)) lo--;
        while (!isprime(hi)) hi++;
        printf("%d %d\n", lo, hi);
    }
}

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

#define MAX 50030

int main()
{
  bool prime[MAX];
  for (int i = 0; i < MAX; i++) prime[i] = true;
  prime[0] = prime[1] = false;
  for (int i = 2; i < sqrt(MAX); i++){
    for (int j = i * 2; j < MAX; j += i){
      prime[j] = false;
    }
  }

  int n;
  while (cin >> n){
    for (int i = n - 1; i > 1; i--) {
      if (prime[i]) {
        cout << i << ' ';
        break;
      }
    }
    for (int i = n + 1; i < MAX; i++){
      if (prime[i]){
        cout << i << '\n';
        break;
      }
    }
  }
}

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

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

int main() {
  eratos();

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