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>
#include <cmath>
using namespace std;
vector<int> sosu(100000, 1);

void eratos() {
  for(int i = 2; i*i < 100000; i++) {
    if(sosu[i] == 1) {
      for(int j = 2; i*j < 100000; 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 < 100000; i++) {
      if(sosu[i] == 1) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#define MAX 100000
using namespace std;
int main(){
    vector<bool> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=v[1]=false;
    for(int i = 2;i<1000;i++){
      if(v[i]){
        for(int j=i*i;j<MAX;j+=i){
         v[j]=false;
       }
      }
    }
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      while(true){
        int i =a;
        i--;
        if(v[i]){
          cout <<i<<' ';
          break;
      }
    }
    while(true){
      int i =a;
      i++;
      if(v[i]){
        cout <<i<<endl;
        break;
     }
   }
 }
}

C++: #include <iostream>
#define MAX_n 50001
using namespace std;
bool is_prime[51000];

void sieve() {

  for(int i=0;i<51000;i++) {
    is_prime[i] = true;
  }

  is_prime[0] = is_prime[1] = false;

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

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

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

C++: #include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 1000000;

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

typedef long long ll;

using namespace std;


/*
class ElectronicPetEasy
{
public:
	string isDifficult(int st1, int p1, int t1, int st2, int p2, int t2)
	{
		
	}
};
*/


int prime[50000];
bool is_prime[50001];


void sieve(void)
{
	int p = 0;
	
	REP(50001) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i=2; i<=50000; i++)
	{
		if (is_prime[i])
		{
			prime[p++] = i;
			for (int j=2*i; j<=50000; j+=i) is_prime[j] = false;
		}
	}
}


int main()
{
	int n, less, more;
	
	sieve();
	
	while (cin >> n)
	{
		less = 2;
		for (int i=0; i<50000; i++)
		{
			if (prime[i] > n)
			{
				more = prime[i];
				break;
			} else if (less < prime[i]) {
				less = prime[i - 1];
			}
		}
		
		cout << less << " " << more << endl;
	}
	
	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

//素数判定
bool isPrime(int n) {
	if (n == 2)return true;
	if (n < 2 || n % 2 == 0)return false;

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

int main() {
	int n;
	while (cin >> n) {
		for (int i = n - 1; true; i--) {
			if (isPrime(i)) { cout << i << " "; break; }
		}

		for (int i = n + 1; true; i++) {
			if (isPrime(i)) { cout << i << endl; break; }
		}
	}
}

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

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

int main() {
	int n;
	while (scanf("%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; }
				}
			}
		}
}

C++: #include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;
bool isPrime(int num);

int main(){
	int n;
	while(cin >> n, n){
		int a = 0;
		int b = 0;
		for(int i = 2; (n-i) >= 3 && (n+i) <= 50000; i += 2){
			if(isPrime(n-i) && a == 0)
				a = n-i;
			if(isPrime(n+i) && b == 0)
				b = n+i;
		}
		cout << a << " " << b << endl;
	}
	return 0;
}

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

C++: #include<stdio.h>
int table[55000];
 
int main(){
    for(int i=2;i<1000;i++){
        if(table[i]==0){
            for(int j=i*2;j<=55000;j+=i){
                table[j]=1;
            }
        }
    }
    int a;
    while(~scanf("%d",&a)){
        int i;
        for(i=a-1;table[i]==1;i--);
        printf("%d ",i);
        for(i=a+1;table[i]==1;i++);
        printf("%d\n",i);
    }
}

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

int main()
{
    int n;
    int max,first;
    bool flag=false;
    while(cin>>n,!cin.eof()){
        for(int i=2;i<n;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i/2<j){
                    max=i;
                }
            }
        }
        cout<<max<<' ';
        bool flag=false;
        for(int i=n+1;;i++){
            for(int j=2;j<i;j++){
                if(i%j==0){
                    break;
                }
                if(i/2<j){
                    first=i;
                    flag=true;
                    break;
                }
            }
            if(flag)break;
        }
        cout<<first<<endl;
    }
    return 0;
}

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; ; d--, u++){
			if( under != -1 && over != -1 ) break;
			if( prime[d] ) under = d;
			if( prime[u] ) over = u;
		}
		cout << under << " " << over << endl;
	}
}