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 P[1000001];

void eratos()
{
	for( int i = 0;i < 1000001;i++ ) P[i] = true;
	P[0] = P[1] = false;
	for( int i = 0;i < 1000001;i++ ){
		if( P[i] ) for( int j = 2;j * i < 1000001;j++ ) P[i * j] = false;
	}
}

int main(void)
{
	int n;

	eratos();
	while( cin >> n ){
		for( int i = n - 1;;i-- ){
			if( P[i] ){ cout << i;
			break;}
		}
		for( int i = n + 1;;i++ ){
			if( P[i] ){ cout << " " << i << endl;
			break;}
		}
	}

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <vector>
#include <list>
#include <algorithm>
#include <cmath>
#include <stack>
#include <map>
using namespace std;

#define REP(i,n) for(int (i)=0; (i)<(n); (i)++)
#define FOR(i,a,b) for(int (i)=(a); (i)<(b); (i)++)
#define PUSH(n,v) for(int i=0; i<(n); i++) {int j; cin >> j; v.push_back(j);}
#define ALL(v) v.begin(), v.end()

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

vector<int> primeList;

void findPrimes(int k) {
    int smallestIndex = 0;
    REP(i,primeList.size()) {
        if (k <= primeList[i]) {
            smallestIndex = i - 1;
            break;
        }
    }
    cout <<primeList[smallestIndex] << " ";
    if (primeList[smallestIndex + 1] == k) {
        cout << primeList[smallestIndex + 2] << endl;
    }else {
        cout << primeList[smallestIndex + 1] << endl;
    }
}

int main() {
    FOR(i,2,51000) {
        if (prime(i)) primeList.push_back(i);
    }
    int k;
    while(cin >> k) {
        findPrimes(k);
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main() {
	int n;
	while (cin >> n) {
		vector<int> pl(n*n, 0);
		vector<int> res(2);
		pl[2] = 1;
		for (int i=3; i<n*n; i+=2) pl[i] = 1;
		for (int i=3; i<n; i+=2) {
			if (pl[i] == 0) continue;
			for (int j=i*2; j<=n*n; j+=i) pl[j] = 0;
		}
		for (int i=n; i>0; i--) {
			if (pl[i]==1) {
				res[0] = i;
				break;
			}
		}
		for (int i=n; i<n*n; i++) {
			if (pl[i]==1) {
				res[1] = i;
				break;
			}
		}
		cout << res[0] << " " << res[1] << endl;
	}
}

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

using namespace std;

int main(){

  int putin;
  int n;
  int i,j;
  int number[50001];

  for(i=0; i<50001; i++){
    number[i] = 1;
  }

  for(i=2; i<100; i++){
    for(j=2; j<500; j++){
      number[i*j] = {0};
    }
  }

  cin >> putin;

  for(n=putin-1; n>0; n--){
    if(number[n]!=0){
      cout << n << endl;
      break;
    }
  }

  for(n=putin+1; n<50000; n++){
    if(number[n]!=0){
      cout << n << endl;
      break;
    }
  } 
}

C++: #include <stdio.h>

#define DATANUM 50001

int maxarray(int va[], int std1);
int minarray(int vb[], int std2);

int main(void) {
    int num[DATANUM] = {0};
    int i, j, std;
    
    
    for(i = 2; i < DATANUM; i++) {
        if(i != 2 && i % 2 == 0) num[i] = 1;
        if(i != 3 && i % 3 == 0) num[i] = 1;
        if(i != 5 && i % 5 == 0) num[i] = 1;
        if(i != 7 && i % 7 == 0) num[i] = 1;
        for(j = 2; j < i; j++) {
            if(!(i % j)) num[i] = 1;
        }
    }
    
    while(scanf("%d", &std) != EOF) {
        printf("%d %d\n", maxarray(num, std), minarray(num, std));
    }

    return(0);
    
}

int maxarray(int va[], int std1) {
    int max, i;
    
    max = 2;
    
    for(i = 2; i < std1; i++) {
        if(i > max && va[i] != 1) {
            max = i;
            printf("max = %d\n", max);
        }
    }
    
    return(max);
}

int minarray(int vb[], int std2) {
    int min, i, count = 0;
    
    for(i = std2 + 1; i <= DATANUM; i++) {
        if(vb[i] != 1 && count == 0) {
            min = i;
            count++;
        }
    }
    
    return(min);
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int sosu[66666];
main(){
  for(int i=2;i<=60000;i++){
    if(sosu[i]==1) continue;
    for(int j=i*2;j<=60000;j+=i){
      sosu[j]=1;
    }
  }
   
  int N;
  while(~scanf("%d",&N))
    {
      int i=N-1;
      while(sosu[i]) i--;
      printf("%d ",i);
      i=N+1;
      while(sosu[i]) i++;
      printf("%d\n",i);
    }
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define MAX 1000000

using namespace std;

int prime[MAX];

int main()
{
	prime[0] = prime[1] = 0;

	REP(i,2,50001)
	{
		prime[i] = 1;
	}

	REP(i,2,50001)
	{
		if(prime[i])
		{
			for(int j = 2;(j*i) <  50001;j++)
			{
				prime[j*i] = 0;
			}
		}
	}

	int n;

	while(cin >> n)
	{
		int under_max = 0,upper_min = 50001;
		rep(i,n)
		{
			if(prime[i] == 1)
			{
				under_max = max(under_max,i);
			}
		}
		REP(i,n+2,50001)
		{
			if(prime[i] == 1)
			{
				upper_min = min(upper_min,i);	
			}
		}

		cout << under_max << " " << upper_min << endl;
	}


	return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> sosu(60000, 1);

void eratos() {
  for(int i = 2; i < 30000; i++) {
    sosu[2*i] = 0;
  }
  for(int i = 3; i*i < 60000; i++) {
    if(sosu[i] == 1) {
      for(int j = 3; i*j < 60000; j++) {
	sosu[i*j] = 0;
      }
    }
  }
}

int main() {
  eratos();

  while(1) {
    int n;
    cin >> n; 
    
    for(int i = n-1; i >= 0; i--) {
      if(sosu[i] == 1) {
	cout << i << ' ';
	break;
      }
    }
    for(int i = n+1; i < 60000; i++) {
      if(sosu[i] == 1) {
	cout << i << endl;
	break;
      }
    }
  }
  return 0;
}

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

#define MAX 60000

int main(void) {
    int prime[MAX] ={};
    int n;
    
    for(int i = 2; i < MAX; ++i) {
        if(prime[i] != 0)   continue;
        int j = i + i;
        while(j < MAX) {
            ++prime[j];
            j += i;
        }
    }
    
    while(cin >> n) {
        int i = n - 1;
        while(i >= 2) {
            if(prime[i] == 0) {
                cout << i;
                break;
            }
            --i;
        }
        i = n + 1;
        while(i < MAX) {
            if(prime[i] == 0) {
                cout << ' ' << i << endl;
                break;
            }
            ++i;
        }
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#define ll long long int
#define ld long double
#define INF 1000000000
#define EPS 0.0000000001
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;
typedef pair<int, int> P;

string str;

int main()
{
  int n;
  int i,j;

  bool prime[55000]={};//?´???°??????
  for(i=2;i<55000;i++){
    if(prime[i])continue;
    else
      for(j=2;i*j<55000;j++)
	prime[i*j]=true;
  }

  while(scanf("%d",&n)!=EOF){
    for(i=n-1;i>1;i--)
      if(prime[i]==false){
	cout<<i<<" ";
	break;
      }
    for(i=n+1;i<55000;i++)
      if(prime[i]==false){
	cout<<i<<endl;
	break;
      }
  }
}