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>

using namespace std;

bool erat[50100];

int main()
{
    for (int i = 2; i*2 <= 50100; i++) {
        erat[0] = true;
        erat[1] = true;
        if (!erat[i]) {
            for (int j = 2; i*j <= 50100; j++) {
                erat[i*j] = true;
            }
        }
    }

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

C++: #include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,n) loop(i,0,n)

const int MAX_N=50100;
int p[(MAX_N+1)/2];
bool isp[MAX_N+1];
int f(){
    memset(isp,1,sizeof(isp));
    isp[0]=isp[1]=false;
    int idx=0;
    loop(i,2,MAX_N+1){
        if(!isp[i]) continue;
        p[idx++]=i;
        for(int j=i+i; j<=MAX_N; j+=i){
            isp[j]=false;
        }
    }
    return idx;
}

int len;

int main(){
    int n;
    len=f();
    while(cin>>n){
        int ub=*upper_bound(p,p+len,n);
        int lb=*(lower_bound(p,p+len,n)-1);
        cout<<lb<<" "<<ub<<endl;
    }
}

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

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

int main(){
	int n,nl,nh;
	while(cin>>n){
		nl=n;
		nh=n;
		while(1){
			nl--;
			if(prime(nl))break;
		}
		while(1){
			nh++;
			if(prime(nh))break;
		}
		cout<<nl<<" "<<nh<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;

#define loop(i, a, b) for(int i = a; i < b ; i++)
#define rep(i, a) loop(i, 0, a)
#define MAX 50022

int main()
{
  bool prime[MAX];
  rep(i, MAX) prime[i] = true;
  prime[0] = prime[1] = false;
  loop(i, 2, sqrt(MAX)){
    for(int j = i * 2; j < MAX; j += i){
      prime[j] = false;
    }
  }
  
  int n;
  while(cin >> n) {
    for(int j = n - 1; j > 1; j--) if(prime[j] == true) {cout << j << ' '; break;}
    loop(i, n + 1, MAX)            if(prime[i] == true) {cout << i << endl; break;}
  }
}

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


#define N 50000

int main(){
    int n;

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


    while(1){
      int counter = 0;
      cin >> n;
      if(n == 0)
        break;
      if(cin.eof())
        break;
      int i=0;
      while(i <= n/2){
        if(is_prime[n-i] && is_prime[i])
          counter++;
        i++;
      }
        cout << counter << endl;
      }

    return 0;
}

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

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

int main(){
	int n,nl,nh;
	while(cin>>n){
		nl=n;
		nh=n;
		while(1){
			nl--;
			if(prime(nl))break;
		}
		while(1){
			nh++;
			if(prime(nh))break;
		}
		cout<<nl<<" "<<nh<<endl;
	}
	return 0;
}

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

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

int main() {
    std::string str;
    int num = 0;
    std::cin >> num;
       for(int i = num-1; 2 < i;i--){
        if(IsPrime(i) == true){
            printf("%d ",i);
            break;
        }
    }
    for(int k = num+1;k < 50022; k++){
        if(IsPrime(k) == true){
            printf("%d\n",k);
            break;
        }
    }
    

}

C++: #include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	int num;
	vector<int> primeList;
	bool used[51000];
	memset(used, true, sizeof(used));

	for(int i = 2; i < 1000; i++)
	{
		if(used[i] == false)
		{
			continue;
		}
		for(int j = i*2; j < 51000; j += i)
		{
			used[j] = false;
		}
	}
	for(int i = 2; i < 51000; i++)
	{
		if(used[i] == true)
		{
			primeList.push_back(i);
		}
	}
	
	while(cin >> num)
	{
		if(binary_search(primeList.begin(), primeList.end(), num))
		{
			printf("%d %d\n",*(upper_bound(primeList.begin(), primeList.end(), num)-2), *upper_bound(primeList.begin(), primeList.end(), num));
		}
		else
		{
			printf("%d %d\n",*(upper_bound(primeList.begin(), primeList.end(), num)-1), *upper_bound(primeList.begin(), primeList.end(), num));
		}	
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
int num[50500],n,ma,anslow=0,anshigh=0;
ma=sqrt(50500);
for(int i=1;i<50500;i++)num[i]=0;
for(int i=2;i<ma;i++){
if(num[i]==0){
for(int j=2;j*i<50500;j++)num[j*i]=1;
}
}
while(cin>>n){
for(int i=1;anslow==0||anshigh==0;i++){
if(num[n-i]==0&&anslow==0)anslow=n-i;
if(num[n+i]==0&&anshigh==0)anshigh=n+i;
}
cout<<anslow<<" "<<anshigh<<endl;
anshigh=0;anslow=0;
}
}

C++: #include <iostream>
#include <vector>
#include <string.h>

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

void calc()
{
	memset(IsPrime, 1, sizeof(bool) * 55000);
	for(int i = 2; i < 55000; ++i)
	{
		if(IsPrime[i])
		{
			Prime.push_back(i);
			for(int j = 2 * i; j < 55000; j += i)
			{
				IsPrime[j] = false;
			}
		}
	}
}

void solve()
{
	calc();
	int n;
	while(cin >> n)
	{
		int pos = 0;
		while(Prime[pos] < n)
		{
			pos++;
		}
		if(IsPrime[n])
		{
			cout << Prime[pos - 1] << " " << Prime[pos + 1] << endl;
		}
		else
		{
			cout << Prime[pos - 1] << " " << Prime[pos] << endl;
		}
	}
}

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

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

const int SIEVE_SIZE = 1000000;

bool sieve[SIEVE_SIZE + 1];
int prime_count[SIEVE_SIZE + 1];

int main()
{
	int i,j,n,l,r;
	
	sieve[0] = sieve[1] = true;
	for (i = 2; i * i <= SIEVE_SIZE; i++){
		if (sieve[i]) continue;
	   	for (j = i*i; j <= SIEVE_SIZE; j += i){
	    	 sieve[j] = true;
	    }
	}
	
	while(scanf("%d", &n) != EOF){
		for(l = n-1; sieve[l] == true; l--);
		for(r = n+1; sieve[r] == true; r++);
		printf("%d %d\n", l, r);
	}
	
	
	return(0);
}