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 100001

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( 0 < 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 <vector>
#include <algorithm>
using namespace std;
#define ll long long
#define REP(i,n) for(int i=0;i<n;i++)
#define PP(m) REP(i, m.size()) cout << m[i] << endl;

vector<bool> isPrime;
ll primed = 0;

void eratosu(ll max){
  if (max < primed) return;
  else primed = max;

  if (max+1 > isPrime.size()) {
    isPrime.resize(max+1,true);
  }
  isPrime[0] = false;
  isPrime[1] = false;

  for(ll i = 2; i * i <= max; ++i) {
    if (isPrime[i]) {
      for(ll j = 2; i * j <= max; ++j) {
        isPrime[i*j] = false;
      }
    }
  }
}

int main() {
  int a, b, c;
  eratosu(50000);
  while (cin >> a && a) {
    b=a-1; c=a+1;
    while (!isPrime[b]) b--;
    while (!isPrime[c]) c++;
    cout << b << " " << c << endl;
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <utility>
#include <numeric>

using namespace std;
typedef long long llong;
typedef unsigned long long ullong;

const ullong MOD = 1000000000 + 7;

// 素数判定
template<typename T>
bool is_prime(T n)
{
	if (n == 2)
	{
		return true;
	}
	else if ((n == 1) || (n % 2 == 0))
	{
		return false;
	}

	T p = (T)sqrt(n);
	for (T i = 3; i <= p; i += 2)
	{
		if (n % i == 0)
		{
			return false;
		}
	}

	return true;
}

int main()
{
	vector<int> prime;

	for (int i = 2; i <= 60000; i++)
	{
		if (is_prime(i))
		{
			prime.push_back(i);
		}
	}

	int n;
	for (; cin >> n;)
	{
		int priv, next;
		for (int i = 0; i < prime.size(); i++)
		{
			if (n == prime.at(i))
			{
				priv = prime.at(i - 1);
				next = prime.at(i + 1);
				break;
			}
			else if (n < prime.at(i))
			{
				priv = prime.at(i - 1);
				next = prime.at(i);
				break;
			}
		}

		cout << priv << " " << next << endl;
	}
}

C++: #include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

// N以下の素数を列挙して返す
vector<ll> enum_prime(ll N){
	deque<bool> is_prime(N+1,true);
	vector<ll> P;
	for(ll i=2;i<=N;i++){
		if(is_prime[i]){
			for(ll j=i*i;j<=N;j+=i){
				is_prime[j] = false;
			}
			P.emplace_back(i);
		}
	}
	return P;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	while(cin>>N){
		auto res = enum_prime(2*N);
		sort(ALL(res));
		auto L = lower_bound(ALL(res),N);
		if(*L>=N) L--;
		auto R = L+1;
		if(*R<=N) R++;
		out(*L,*R);
	}
	
	return 0;
}

C++: #include <iostream>

using namespace std;

bool prime_table[10000];
int n;

void make_table() {
    for (int i = 0; i < 10000; i++) 
        prime_table[i] = true;

    prime_table[0] = false;
    prime_table[1] = false;

    for (int i = 2; i + i < 10000; i++) {
        if (prime_table[i]) {
            for (int j = i + i; j < 10000; j += i) {
                prime_table[j] = false;
            }
        }
    }
}

void solve() {
    int min, max;
    int i;
    for (i = n-1; !prime_table[i]; i--);
    min = i;

    int j;
    for (j = n+1; !prime_table[j]; j++);
    max = j;
    cout << i << ' ' << j << endl;
}

int main() {
    make_table();
    while (cin >> n) {
        solve();
    }
    return 0;
}

C++: using System;
using System.Collections.Generic;

namespace _0044
{
    class Programｓ
    {
        static void Main(string[] args)
        {
            List<int> primeList = new List<int>();
            for (int i = 1; i < 50022; i++)
            {
                if (IsPrime(i))
                {
                    primeList.Add(i);
                }
            }

            while (true)
            {
                var input = Console.ReadLine();

                if (string.IsNullOrEmpty(input)) { break; }

                int number = int.Parse(input);
                int previousPrimeNumber = 0;
                int nextPrimeNumber = 0;

                foreach (var primeNumber in primeList)
                {
                    if (primeNumber < number)
                    {
                        previousPrimeNumber = primeNumber;
                    }
                    else if (primeNumber > number)
                    {
                        nextPrimeNumber = primeNumber;
                    }

                    if (nextPrimeNumber != 0)
                    {
                        break;
                    }
                }
                Console.Write("{0} {1}\n", previousPrimeNumber, nextPrimeNumber);
            }
        }
        public static bool IsPrime(int number)
        {
            if (number <= 1)
            {
                return false;
            }
            else if (number <= 3)
            {
                return true;
            }
            else if ((number % 2) == 0)
            {
                return false;
            }
            else
            {
                for (int i = 3; i <= (int)Math.Sqrt(number); i += 2)
                {
                    if (number % i == 0)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}

C++: #include<iostream>
#include<vector>
#include<cmath>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a; i ++)
#define loop(i,b,a) for(int i = b ; i < a; i ++)
const int MAX = (1e6);
bool p[MAX];
void isPrime(){
  fill(p,p + MAX,true);
  p[0] = p[1] = false;
  rep(i,MAX){
    if(p[i]){
      for(int j = i + i ; j < MAX ; j += i)
    p[j] = false;
    }
  }
} 
 
int main(void){
  isPrime();
  int n;
  while(cin>>n){
  int i = n-1;
  while(!p[i--]);
  cout<<++i<<' ';
  i = n + 1;
  while(!p[i++]);
  cout<<--i<<endl;
  }
  return 0;
}