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<cstdio>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<string>
#include <vector>
#include <map>
#include<cstdio>
#include<cstdlib>

using namespace std;

void Solution()
{
    int N = 105000; // to judge if the number is prime number
    int n;
    bool data[N];
    
    for(int i = 0;i < N; i++)
    {
        if(i % 2 == 0) // remove the numbers which can be devide by 2
        {
            data[i] = false;
        }
        else
        {
            data[i] = true;
        }
    }
    
    data[1] = false; //remove 1
    data[2] = true; // casue 2 is prime number
    
    for(int i = 3; i < N; i += 2) // remove 3, 5, 7's multiples
    {
        if(data[i])
        {
            for(int j = i + i; j < N; j += i) //remove 3, 5, 7's multiples
            {
                data[j] = false;
            }
        }
    }
   
    while(cin>>n)
    {
        
                
        for(int i = n - 1; i > 1; i--)
        {
            if(data[i])
            {
                cout<<i;
                break;
            }
        }
        
        for(int i = n + 1; i < N; i++)
        {
            if(data[i])
            {
                cout<<" "<<i<<endl;
                break;
            }
        }
        
    }
}

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

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

int main()
{
	int n;
	while (cin>>n) 
	{
		bool prime[500000];
		fill(prime,prime+500000,0);
		vector<int> nums;
		for(int i = 2; i < 500000; ++i)
		{
			if(prime[i]) continue;
			nums.push_back(i);
			for(int j = i*2; j < 500000; j+=i)
			{
				prime[j]=true;
			}
		}

		vector<int>::iterator it=lower_bound(nums.begin(),nums.end(),n);
		if(*(it-1)==n) cout<<*(it-1);
		else cout<<*(it-2);

		it=upper_bound(nums.begin(),nums.end(),n);
		cout<<" "<<*it<<endl;
	}
  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#define MAX_N 50000
using namespace std;

bool prime[MAX_N + 1];

bool isPrime(int n) {
    //今回、０、１をこの関数の引数に取らない
    for(int r = 2; r * r <= n; r++) {
        if(n % r == 0) return(false);
    }
    return(true);
}

void initialize() {
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = false; //0,1は素数ではない。
    for(int r = 2; r <= MAX_N; r++) {
        if(isPrime(r)) {
            for(int c = r * 2; c <= MAX_N; c += r) prime[c] = false; //倍数は素数で無い事が分かっている
        }
    }
}

int searchSmall(int num) {
    for(int r = num - 1; r >= 0; r--)
        if(isPrime(r)) return(r);
    return(-1);
}

int searchLarge(int num) {
    for(int r = num + 1; r <= MAX_N; r++)
        if(isPrime(r)) return(r);
    return(-1);
}

int main(void) {
    initialize();
    
    int input;
    while(cin >> input) {
        int max = searchSmall(input), min = searchLarge(input);
        cout << max << " " << min << endl;
    }
    return(0);
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>

using namespace std;

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

int main() {
    int N;
    while (cin >> N) {
        int p1, p2;
        for (p1=N-1; ; p1--) {
            if (is_prime(p1)) break;
        }
        for (p2=N+1; ; p2++) {
            if (is_prime(p2)) break;
        }
        cout << p1 << " " << p2 << endl;
    }
    return 0;
}

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

int main(){
    int n[60001];
    memset(n,0,sizeof(n));
    for(int i=2;i<30001;i++)
        for(int j=i;i*j<60001;j++)
            n[j*i]=1;
    int f,i;
    while(cin>>f){
        for(i=f-1;n[i];i--);cout<<i<<" ";
        for(i=f+1;n[i];i++);cout<<i<<endl;
    }
}

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

int main(){
	bool b[MAX];
	fill(b, b+MAX, false);b[0] = b[1] = true;
	for(int i = 2;i < MAX;i++){
		if(!b[i]){
			for(int j = 2;i*j < MAX;j++){
				b[i*j] = true;
			}
		}
	}
	
	int n, x, y;
	while(cin >> n){
		for(x = n-1;b[x];x--);
		for(y = n+1;b[y];y++);
		cout << x << " " << y << endl;
	}
	return 0;
}
/*
1
y eazqyp pnop pngtg ye obmpngt xmybp mr lygw
*/

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

using namespace std;

int main(){
  
  int n,a,b;
  int flag=0;

  while(cin>>n){
  for(int i=n-1;i>=1;i--){
    for(int j=2;j<=sqrt((double)i);j++){
      if(i%j==0){
        flag=1;
        break;
      }
    }
    if(flag==0){
      a=i;
      break;
    }
    else
      flag=0;
  }

  for(int i=n+1;i<60001;i++){
    for(int j=2;j<=sqrt((double)i);j++){
      if(i%j==0){
        flag=1;
        break;
      }
    }
    if(flag==0){
      b=i;
      break;
    }
    else
      flag=0;
  }

  cout<<a<<" "<<b<<endl;
  }
  return 0;
}

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

bool prime[MAX];
void calcPrime(){
	for(int i = 0; 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, u = n; 2 < d || u < MAX; ){
			if( under != -1 && over != -1 ) break;
			if( under == -1 && 2 < d ){
				d--;
				if( prime[d] ) under = d;
			}
			if( over == -1 && u < MAX ){
				u++;
				if( prime[u] ) over = u;
			}
		}
		cout << under << " " << over << endl;
	}
}