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;
#define MAX 1000000

int prime[MAX];

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

int main(void){
  int n;

  is_prime();

  while(cin >> n){
    for(int i = n-1 ; prime[i] == 0 ; i--);
    cout << i << ' ';

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

  return 0;
}

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

int smallprime(int x)
{
		for(int i=x-1; ; i--)
		{
			if((i%2==0) ||(i%3==0) || (i%4==0)||(i%5==0)||(i%6==0) || (i%7==0) || (i%8==0) || (i%9==0))
			continue;
		else
		{
			if((i/1==i) && (i/i==1))
				return i;
			break;
		}
		}
	}

	int bigprime(int x)
	{
		for(int i=x+1; ; i++)
		{
			if((i%2==0) ||(i%3==0) || (i%4==0)||(i%5==0)||(i%6==0) || (i%7==0) || (i%8==0) || (i%9==0))
			continue;
		else
		{
			if((i/1==i) && (i/i==1))
				return i;
			break;
		}
		}
	}
	int main()
	{
		int x;
		while(cin>>x)
		{
			
			
			{
				cout<<smallprime(x)<<" "<<bigprime(x)<<endl;
			}
		}
		return 0;
	}

C++: #include<iostream>
using namespace std;
#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
const int M = (1e6);
int p[M];
void isPrime(){
  rep(i,M)p[i] = true;
  p[0] = p[1] = false;
  loop(i,2,M){
    if(p[i])
      for(int j = i + i ; j < M ; j += i)
	p[j] = false;
  }
}
int main(void){
  isPrime();
  int n;
  while(cin>>n){
    int i = n - 1;
    while(!prime[i]);cout<<i<<" ";
    i = n + 1;
    while(!prime[i]);cout<<i<<endl;
  }
}

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


int prime[60000];


void sieve(){
	memset(prime, 1, sizeof prime);
	int i;
	for(i = 2;i*i <= 60000;i++){
		if(prime[i]){
			for(int j = 2;i*j <= 60000;j++){
				prime[i*j] = 0;
			}
		}
	}
}


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

C++: #include <iostream>
#include <math.h>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		bool prime[1000000];
		for(int i=2;i<=999999;i++){
			prime[i]=true;
		}
		for(int j=2;j<=999999;j++){
			if(prime[j]){
				for(int k=j*2;k<=999999;k+=j){
					prime[k]=false;
				}
			}
		}
		int a,b;
		for(int l=2;l<n;l++){
			if(prime[l]==true) a=l;
		}
		for(int m=n+1;m<=999999;m++){
			if(prime[m]==true){
				b=m;
				break;
			}
		}
		cout<<a<<" "<<b<<endl;
	}
	return 0;
	
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <string>
#define rep(x,to) for(int x=0;x<to;x++)
#define rep2(x,from,to) for(int x=from;x<to;x++)
#define num  50111

using namespace std;




int main(void){
 
int innum;
 
	bool Find[num] ; // 探索リスト
    for(int i = 2; i <= num; i++){
        Find[i] = true;
        if(i%2==0) Find[i] = false;
    }
    for(int i = 2; i*i < num; i++){
        if(Find[i] == false) continue; // すでに除いた数は飛ばす
        for(int j = i * 2; j< num; j += i) {
            if(Find[j]) Find[j] = false;
        }
    }
    Find[2]= true;
//	rep(i,200) if(Find[i]) cout << i << " ";
    while(cin >> innum){
    	for(int i=innum-1;;i--){
    		if(Find[i]){
    			cout << i << " "; 
             	break;  }
        }
    	for(int i=innum+1;;i++){
    		if(Find[i]){
    			cout << i ; 
            	break; }
        }
		cout << endl;
    }
    return 0;
}

C++: // 素数を和を求めるプログラム
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>

using namespace std;

int main(void)
{
    bool flag = true;
    int n, num, last_num, loop_count = 0;
    vector<int> prime;

    // 初期値の設定
    num = last_num = 2;
    prime.push_back(num);

    while( loop_count < 50)
    {
        cin >> n;
        // 前回見つかった最後の素数値を代入
        num = last_num;

        // 素数を探索する処理
        while( last_num <= n )
        {
            num++;
            flag = true;

            for(unsigned int i = 0; i < prime.size(); i++)
            {
                if( num % prime[i] == 0 )
                {
                    // 素数で割り切れる数は, 素数ではない
                    flag = false;
                    break;
                }
            }

            if( flag == true )
            {
                // 素数が見つかった
                prime.push_back(num);
                // 見つかった最後の素数を記憶する
                last_num = num;
            }
        }

        for(unsigned int i = 0; i < prime.size(); i++)
        {
            // 目的の素数値の前後の値を表示する
            if( prime[i] == n )
            {
                printf("%d %d\n", prime[i - 1], prime[i + 1]);
            }
        }

        loop_count++;

    }

    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <stack>
#include <set>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;

void sieve(bool* a){
	for(int i=2;i<=sqrt(50000.);++i){
		if(a[i]){
			for(int j=i*2;j<=50000;j+=i){
				a[j]=false;
			}
		}
	}
}

int main(){
	int n;
	bool a[50001];
	memset(a , true , sizeof(a));
	a[0]=a[1]=false;
	sieve(a);
	while(cin>>n){
		int i,j;
		for(i=n-1;i>=2;--i){
			if (a[i]==true) break;
		}
		for(j=n+1;j<=50000;++j){
			if(a[j]==true) break;
		}
		cout << i << " " << j << endl;
	}
	return 0; 
}

C++: #include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

bool e[52525];

int main(){
  REP(i,52525)e[i]=true;
  e[0]=false;
  e[1]=false;
  int iter = 2;
  set<int> ps;
  while(iter < 52525){
    if(!e[iter]){
      ++iter;
      continue;
    }
    ps.insert(iter);
    int st = iter*2;
    while(st < 52525){
      e[st]=false;
      st+=iter;
    }
    ++iter;
  }
  int n;
  while(~scanf("%d",&n)){
    set<int>::iterator iter;
    iter = ps.lower_bound(n);
    int x,y;
    if(*iter == n){
      --iter; x = *iter;
      ++iter; ++iter; y = *iter;
    }else{
      y = *iter;
      --iter; x = *iter;
    }
    cout<<x<<" "<<y<<endl;
  }
  return 0;
}