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 num[50001];
int main()
{
	int n;
	while(cin >> n)
	{
		num[0]=num[1]=true; for(int i=2;i<=n;i++) num[i]=false;
		int ansup,anslow;
		for(int i=2;i<=50000;i++)
		{
			if(num[i]==false)
			{
				for(int j=i*2;j<=50000;j+=i) num[j]=true;
			}
		}
		for(int j=n+1; ;j++) if(num[j]==false) {ansup=j; break;}
		for(int j=n-1; ;j--) if(num[j]==false) {anslow=j; break;}
		cout << anslow << ' ' << ansup << '\n' ;
	}
}

C++:  
 #include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 bool is_prime(int x)
 {
   for(int i=2;i<=(int)sqrt(x);i++)
   {
     if(x%i==0) return false;        
   }     
   return true;
 }
 
 int main()
 {
   int N;
   while(cin>>N)
   {
     int min=N;
     int max=N;
     while(min--) if(is_prime(min)) break;   
     while(max++) if(is_prime(max)) break;
     cout<<min<<" "<<max<<endl;            
   }
   //while(1);
   return 0;
 }

C++: #include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
using namespace std;


int main(){

  vector<bool> prime(60000, true);
  prime[0] = false;
  prime[1] = false;
  for(int i=2; i<60000; i++){
    if( !prime[i] ) continue;
    for(int j=i*2; j<60000; j+=i){
      prime[j] = false;
    }
  }

  int n;
  while(cin >> n){
    int tmp = 2;
    for(int i=n-1; i>=0; i--){
      if( prime[i] ){
        tmp = i;
        break;
      }
    }
    for(int i=n+1; i<60000; i++){
      if( prime[i] ){
        cout << tmp << " " << i << endl;
        break;
      }
    }
  }

  return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <sstream>
#include <vector>
#include <string>
#include <iomanip>
#include <bitset>
#define INF	100000000
#define pb	push_back
#define fi first
#define sec second
#define SS stringstream
using namespace std;
typedef pair<int, int> P;
typedef long long int	ll;

int sosuu[60001] = {false};

int main(){
	int a = 60000;
	int n;
	int x;
	x = floor(sqrt(a));
	for(long long int i = 2; i < x+1; i++){
		if(sosuu[i] == true){
			continue;
		}
		for(long long int j = 2*i; j < a+1; j = j+i){
			sosuu[j] = true;
		}
	}
	while(cin >> n){
		int s, l;
		for(int i = 1;; i++){
			if(sosuu[n-i] == false){
				s = n-i;
				break;
			}
		}
		for(int i = 1;; i++){
			if(sosuu[n+i] == false){
				l = n+i;
				break;
			}
		}
		cout << s << " " << l << endl;
	}
}

C++: #include<iostream>

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

int main()
{
	int n;
	while( std::cin >> n ){
		int a = n;
	 	while( !isprime( --a ) );
		std::cout << a << " ";
		a = n;
		while( !isprime( ++a ) );
		std::cout << a << std::endl;
	}
	
 	return 0;
}

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

int main()
{
    int prime[30000];
        prime[0] = 2;
    int num = 1, n;

    for(int i=3; i<50000; i++){
        bool f = true;
        for(int j=0; j<num; j++){
            if(i%prime[j] == 0){
                f = false;
                break;
            }
        }
        if(f){
            prime[num] = i;
            num++;
        }
    }

    while(cin >> n, n){

        int i;

        for(i=0; prime[i]<=n; i++){
        }
        cout << prime[i-1] << ' ' << prime[i] << endl;
    }

    return 0;
}

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

using namespace std;

int main() {
	int n;
	int hyou[50000] = {1};
	for (int i = 1; i < 50000; i++) {
		if (hyou[i] == 0) {
			for (int j = 2; (i+1) * j < 50000; j++) {
				hyou[(i+1)*j-1] = 1;
			}
		}
	}
	while (cin >> n) {
		for(int i = n-2; i >= 0; i--) {
			if (hyou[i] == 0) {
				cout << i+1 << " ";
				break;
			}
		}
		for (int i = n; i < 50000; i++) {
			if (hyou[i] == 0) {
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;

}

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 "bits/stdc++.h"
using namespace std;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main(){
  long long int n;
  while(cin>>n){
    for(int i=n-1;i>1;i--){
      if(IsPrime(i)){
        cout<<i<<" ";
        break;
      }
    }
    for(int i=n+1;;i++){
      if(IsPrime(i)){
        cout<<i<<endl;
        break;
      }
    }
  }
}

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

int is_prime[MAX+2];

void tenesu(void){

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

  for( int i = 0 ; i*i < MAX + 1; i++ ){
    if( is_prime[i] ){
      for( int j = 2*i ; j < MAX + 1; 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>
using namespace std;
int main(){
  int n;
  cin >> n;
  int math[100000]={0};
  math[1]=1;
  for(int i=2;i<100000;i++){
    int bell=i;
    while(bell+i<=100000){
      bell+=i;
      if(math[bell]==0){
	math[bell]=1;
      }
    }
  }

  int hess=n;
  while(1){
    hess--;
    if(math[hess]==0){
      cout << hess << " ";
      break;
    }
  }

  hess=n;
  while(1){
    hess++;
    if(math[hess]==0){
      cout << hess << endl;
      break;
    }
  }

  return (0);
}

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

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

int main() {
	int n,min,max;
	while(cin>>n){
		bool f1=false,f2=false;
		for(int i=1;i<n;i++){
			if(!f1){
				f1=isPrime(n-i);
				if(f1){min=n-i;}
			}
			if(!f2){
				f2=isPrime(n+i);
				if(f2){max=n+i;}
			}
		}cout<<min<<" "<<max<<endl;
	}
	return 0;
}