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++: #define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int n;
    while (cin >> n)
    {
        int p[2 * n] = {};
        for (int i = 2; i <= (int)sqrt(2 * n); i++)
        {
            if (p[i] == 0)
            {
                for (int j = 2; i * j <= 2 * n; j++)
                {
                    p[i * j] = 1;
                }
            }
        }
        int bp, ap;
        for (int i = n - 1; i >= 2; i--)
        {
            if (p[i] == 0)
            {
                bp = i;
                break;
            }
        }

        for (int i = n + 1; i <= 2 * n; i++)
        {
            if (p[i] == 0)
            {
                ap = i;
                break;
            }
        }
        cout << bp << " " << ap << endl;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <math.h>
#include <map>
#include <stdio.h>
#include <ctype.h>
#include <algorithm>
#include <stdlib.h>
#include <stack>
#include <queue>
#include <bitset>
#include <memory.h>

using namespace std;



int sosuu(int x){
    for(int i=2; i<=sqrt(x); i++){
        if(x%i==0)return 0;
    }
    return 1;
}


int main() {
    
    int x;
    while(cin>>x){
        int p;
        int m;
        p=x+1;
        m=x-1;
        
        while(1){
            if(sosuu(m)==1){
                cout<<m<<" ";
                break;
            }else{
                m--;
            }
        }
        
        while(1){
            if(sosuu(p)==1){
                cout<<p<<endl;
                break;
            }else{
                p++;
            }
        }

    }
    return 0;
}

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

#define f first
#define s second

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

#define MAX (50100)
int main(){
  vector<bool> isP(MAX,true);
  isP[0] = isP[1] = false;
  for(int i=2; i*i<MAX; i++){
    if(isP[i]){
      for(int j=i+i; j<MAX; j+=i){
	isP[j] = false;
      }
    }
  }
  int n;
  while(cin>>n){
    for(int i = n-1; ; i--){
      if(isP[i]){
	cout << i;
	break;
      }
    }
    cout << " ";
    for(int i = n+1; ; i++){
      if(isP[i]){
	cout << i;
	break;
      }
    }
    cout << endl;
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#define NUM 100000
using namespace std;
int main(){
  int n, prime[NUM], p[NUM],c=0;
  for(int i=0; i<NUM; i++){
   prime[i] = 0;
   p[i] = 0;
  }
  prime[0] = 1;
  for(int i=2; i<=NUM/2; i++){
      for(int j=2; i*j <= NUM; j++){
	if(prime[i*j-1] == 0)
	  prime[i*j-1] = 1;
      }
  }
  
  for(int i=0; i<NUM; i++){
    if(prime[i] == 0){
      p[c] = i+1;
      c++;
    }
  }

  while(cin >> n){
    if(n < 3 || n > 50000) return 0;
    for(int i=0; i<NUM; i++){
      if(n == p[i]){
      	  c=i;
      	  break;
      }
    }
    cout << p[c-1] << " " << p[c+1] << endl;
  }
  return 0;
  
}

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

int is_prime[MAX];

void tenesu(void){

  for( int i = 0 ; i < MAX ; i++ ) is_prime[i] = 1;
  is_prime[0] = is_prime[1] = 0;

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


int main(void){

  tenesu();

  int n; 
  while( cin >> n ){

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

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

  }
  return 0;
}

C++: #include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
	if(n==3)
		cout<<"2 5"<<endl;
	else{
	int i=n-1;
	while(true){
		bool t=true;
		for(int j=2;j<1+(double)sqrt((double)i);j++){
			if(i%j==0)
				t=false;
		}
		if(t==true)
			break;
		i--;
	}
	cout<<i<<" ";
	i=n+1;
	while(true){
		bool t=true;
		for(int j=2;j<1+(double)sqrt((double)i);j++){
			if(i%j==0)
				t=false;
		}
		if(t==true)
			break;
		i++;
	}
	cout<<i<<endl;
	}
	}
	return 0;
}

C++: #include<iostream>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
using namespace std;

bool isPrime(int p){
	
	if(p<2)return false;
	if(p==2)return true;
	if((p&1)==0)return false;
	
	for(int x=2;x<=sqrt(p);++x)if(p%x==0)return false;

	return true;
}	

int main(){
	int n;
	while(cin>>n){
		int j = n-1;
		while(!isPrime(j))j--;
		cout<<j<<" ";
		j = n+1;
		while(!isPrime(j))j++;
		cout<<j<<endl;
	}
	return 0;
}

C++: #include<iostream>
int main(){
	int n;
	while(std::cin>>n){
		int a=n,b=n,e,d;
		while(1){
			int count=0;
			if(a<50000)a--;
			else{
				d=a;
				break;
			}
			for(int i=2;i<a/2;i++){
				if(a%i==0)count++;
			}
			if(count==0){
				d=a;
				break;
			}
		}
		while(1){
			int count=0;
			if(b<50000)b++;
			else{
				e=b;
				break;
			}
			for(int i=2;i<b/2;i++){
				if(b%i==0)count++;
			}
			if(count==0){
				e=b;
				break;
			}
		}
		std::cout<<d<<" "<<e<<std::endl;
	}
	return 0;
}

C++: #include<iostream>
using namespace std;
bool f(int a)
{
    for(int i=2;i*i<=a;i++)if(a%i<1)return 0;
    return 1;
}
main()
{
    int n;
    while(cin>>n)
    {
        int m=n-1;
        while(!f(m))m--;
        cout<<m<<" ";
        n++;
        while(!f(n))n++;
        cout<<n<<endl;
    }
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

int main (int argc, char *argv[]) {
    const int NUM = 50001;
    vector<bool> prime(NUM, true);
    prime[1] = false;
    for (int i = 2; i < NUM; ++i) {
        if (prime[i]) {
            for (int j = i + i; j < NUM; j+=i) {
                prime[j] = false;
            }
        }
    }
    int n, u, d;
    while (cin>>n) {
        for (int i = n-1; i > 1; --i) {
            if (prime[i]) {
                d = i;
                break;
            }
        }
        for (int i = n + 1; i < NUM; ++i) {
            if (prime[i]) {
                u = i;
                break;
            }
        }
        cout << d << " " << u << endl;
    }
    return 0;
}