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

vector<int> sieve(int n) {
  vector<int> prime(n);
  for(int i=2; i<n; i++) prime[i]=i;
  for(int i=2; i*i<n; i++) {
    if(prime[i])  {
      for(int j=i*i; j<n; j+=i) prime[j]=0;
    }
  }

  return prime;
}

int main() {
  int n;
  vector<int> prime;
  prime = sieve(50022);

  while(cin >> n) {
    int count=0;
    vector<int>::iterator it;

    for(int i=n-1; i>=2; i--) {
      if(prime[i]!=0) {
	cout << i << " ";
	break;
      }
    }
    for(int i=n+1; i<50022; i++) {
      if(prime[i]!=0) {
	cout << i <<endl;
	break;
      }
    }
  }
  return 0; 
}

C++: #include<stdio.h>

int sosu_high_min(int n);
int sosu_small_max(int n);

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
		int high=0,min;
		if(n<3||50000<n)
		{
		}
		else
		{
			high=sosu_small_max((n-1));
			min=sosu_high_min((n+1));
			printf("%d %d\n",high,min);
		}
	}
}

int sosu_small_max(int n)
{
	int t;
	for(n;;n--)
	{
		for(t=2;t<=n;t++)
		{
			if(t==n)
			{
				return n;
			}
			else if(n%t==0)
			{
				break;
			}
		}
	}
}
int sosu_high_min(int n)
{
	int t;
	for(n;;n++)
	{
		for(t=2;t<=n;t++)
		{
			if(t==n)
			{
				return t;
			}
			else if(n%t==0)
			{
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#define loop(i,b,n) for(int i = b; i<n; i++)
#define rep(i,n)  loop(i,0,n)
#define INF 10000
#define  MAX 1e6
using namespace std;

int main (){
    vector<bool>check(MAX+1);
    rep(i, MAX+1)
    check[i] = true;
    vector<int>Primenumber(MAX+1,0); //Primearray
    int counter =0;                  //Primearray counter;
    for(int i = 2; i<MAX+1;i++){
        if(check[i]){
            for(int j = 2;i*j<MAX;j++)
                check[i*j] = false;//?´???°??????Primearray???????´??????????????????°?????¨???false???
            Primenumber[counter] = i;
            counter++;
        }
    }
    int n; while(cin >> n){
    int bigans = 0,sans= 0;
    for(int i = n+1 ;n<INF;i++)
        if(check[i]){bigans = i; break;}
    for(int i = n-1; i>1;i--)if(check[i]){sans = i; break;}
        cout << sans << " " << bigans<< endl;  }  return 0;
}

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

using namespace std;

vector<int> primes;
bool isPrime[50000];

void erats(){
	fill(isPrime,isPrime+50000,true);
	isPrime[0]=false;
	isPrime[1]=false;
	for(int i = 2; i < 50000; i++){
		if(isPrime[i]){
			primes.push_back(i);
			for(int j = 2*i; j < 50000; j+=i){
				isPrime[j]=false;
			}
		}
	}
}


int main(){

	int n;
	erats();
	while(cin>>n&&n!=0){
		for(int j = n-1; ; j--){
			if(isPrime[j]){
				cout<<j<<" "<<flush;
				break;
			}
		}
		for(int j = n+1; ;j++){
			if(isPrime[j]){
				cout<<j<<endl;
				break;
			}
		}
	}

	return 0;
}

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


using namespace std;


vector<int> CreatePrimes(int n)
{
	bool* work = new bool[n+1];
	for (int i = 0; i <= n; ++i)
		work[i] = true;
	work[0] = work[1] = false;

	vector<int> res;
	res.push_back(2);
	for (int i = 4; i <= n; i += 2)
		work[i] = false;

	int until = (int)sqrt((double)n);
	for (int i = 3; i <= n; i += 2)
	{
		if (work[i])
		{
			res.push_back(i);
			for (int j = 2*i; j <= n; j += i)
				work[j] = false;
		}
	}

	return res;
}

int main()
{
	int n;
	vector<int> primes = CreatePrimes(51000);
	while (scanf("%d", &n) != EOF)
	{
		vector<int>::iterator it = lower_bound(primes.begin(), primes.end(), n);
		printf("%d %d\n", *(it-1), *(it+1));
	}

	return 0;
}

C++: #define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <climits>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
typedef pair<int, int> pii;

int memo[60000] = {};
vector<int> pri;
void calc()
{
	for (int i = 2; i < 60000; i++)
	{
		if (memo[i] == 0)
		{
			pri.push_back(i);
			for (int l = i; l < 60000; l += i)
			{
				memo[l] = 1;
			}
		}
	}
}

int main()
{
	calc();
	int n;
	while (cin >> n)
	{
		cout << *(lower_bound(all(pri), n)-1) << " " << *(upper_bound(all(pri), n)) << endl;
	}
}

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

int main(int argc, char** argv) {
	int n;
	while (cin >> n) {
		bool data[200050] = { 0 };
		for (int j = 4; j < 50001; j = j + 2) {
			data[j] = 1;
		}
		for (int i = 3; i < 50001; i = i + 2) {
			for (int j = 2 * i; j < 50001; j = j + i) {
				data[j] = 1;
			}
		}

		for (int i = n - 1; i >= 2; --i) {
			if (!data[i]) {
				cout << i;
				break;
			}
		}
		for (int i = n + 1; i < 50001; ++i) {
			if (!data[i]) {
				cout << " " << i << endl;
				break;
			}
		}
	}
}

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

int main(){
  int table[50001]={};
  for(int i=2; i<10000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=50001; j+=i){
        table[j]=1;
      }
    }
  }
  int n;
  while(cin >> n,n){
    int i;
    for(i=n-1; table[i]; --i);
    cout << i << " ";
    for(i=n+1; table[i]; ++i);
    cout << i << endl;
  }
}

C++: #include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)

using namespace std;
typedef long long ll;

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

int main(){
    int n;
    while(cin>>n){
        for(int i=n-1;i>=2;i--){
            if(isPrime(i)){
                cout<<i<<" ";
                break;
            }
        }
        for(int i=n+1;i<100000;i++){
            if(isPrime(i)){
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

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

int prime[MAX];

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

int main(void){
  int n;

  p();
  while(cin >> n){
    int key = 1;
    while(1){
      if(n == prime[key]){
        cout << prime[key-1] << ' ' << prime[key+1] << endl;
        break;  
      }
      else key++;
    }
  }

  return 0;
}