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;

typedef long long ll;

const int pMax = 6000, nMax = 60000;
ll prime[pMax];
bool is_prime[nMax + 10];

void sieve(ll n) {
	int p = 0;
	for (ll i = 0; i <= n; i++) is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (ll i = 2; i <= n; i++) {
		if (is_prime[i]) {
			prime[p++] = i;
			if (p == pMax) return;
			for (ll j = 2 * i; j <= n; j += i) is_prime[j] = false;
		}
	}
}
int main() {
	sieve(nMax);
	int n;
	while (cin >> n && n) {
		int p = 0, q = pMax - 1;
		while (1) {
			if (prime[p] >= n) break;
			p++;
		}
		while (1) {
			if (prime[q] <= n) break;
			q--;
		}
		cout << prime[p - 1] << " " << prime[q + 1] << endl;
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  vector<int> primenum;
  primenum.push_back(2);
  for(int i=3;i<=50000;i+=2){
    int k=0;
    for(int j=3;j<=sqrt(i);j+=2){
      if(i%j==0){
	k=1;
	break;
      }
    }
    if(k==0)
      primenum.push_back(i);
  }
  int num;
  while(cin>>num){
    for(int i=0;i<primenum.size();i++){
      if(primenum[i]==num){
	cout<<primenum[i-1]<<" "<<primenum[i+1]<<endl;
	break;
      }else if(primenum[i]>num){
	cout<<primenum[i-1]<<" ";
	cout<<primenum[i]<<endl;
	break;
      }
    }
  }
  return 0;
}

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

bool ary[60010];
int main(){
	vector<int> prm;
	for(int i=2;i<=60000;i++){
		if(!ary[i]){
			prm.push_back(i);
			for(int j=i+i;j<=60000;j+=i){
				ary[j]=true;
			}
		}
	}
	int N,ma,mi;
	vector<int>::iterator it;
	while(cin>>N){
		it=upper_bound(prm.begin(),prm.end(),N);
		ma=(*it);
		while((*it)>=N) it--;
		mi=(*it);
		cout<<mi<<" "<<ma<<endl;
	}
	return 0;
}

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

vector<int> sieve(int n) {
	vector<int> res(1, 2);
	vector<bool> prime(n, true);
	for(int i = 3; i < n; i += 2) {
		if(prime[i]) {
			res.push_back(i);
			for(int j = i * 3; j < n; j += i * 2)
				prime[j] = false;
		}
	}

	return res;
}

int main() {
	vector<int> prime = sieve(51000);

	for(int n; scanf("%d", &n) == 1;) {
		int idx = lower_bound(prime.begin(), prime.end(), n) - prime.begin();
		printf("%d %d\n", prime[idx - 1], prime[idx + 1]);
	}

	return EXIT_SUCCESS;
}

C++: #include<iostream>
#include<cstdio>

int main()
{
	int a[50001]={0};
	int i,j;
	int n,c;

	a[2]=1;
	for(i=3;i<=50001;i+=2){
		if(a[i]==2)
			continue;
		else if(a[i]==0){
			a[i]=1;
			for(j=i*2;j<=50001;j+=i)
				a[j]=2;
		}
	}
	while(scanf("%d",&n)!=EOF){
		for(i=n-1;i>1;i--){
			if(a[i]==1){
				printf("%d ",i);
				break;
			}
		}
		for(i=n+1;i<=50001;i++)
			if(a[i]==1){
				printf("%d\n",i);
				break;
			}
	}
	return 0;
}

C++: #include<cstdio>
#include<iostream>
#include<cmath>

#define NMAX 50000
#define YES 0
#define NO 1

using namespace std;

int main(void){

	int hurui[NMAX]={YES};

	hurui[0]=NO,hurui[1]=NO;
	for(int i=2;i<sqrt((double)NMAX);i++){
		if(hurui[i]==YES){
			for(int j=i+i;j<NMAX;j+=i){
				hurui[j]=NO;
			}
		}
	}

	int inp;

	while(cin>>inp){
		for(int i=inp-1;;i--){
			if(hurui[i]==YES){
				cout<<i<<" ";
				break;
			}
		}
		for(int i=inp+1;;i++){
			if(hurui[i]==YES){
				cout<<i<<endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include <iostream>
using namespace std;
int main(void)
{
	int prime[50000];
	prime[0] = 2;
	prime[1] = 3;
	int ptr = 2;
	for(int num = 5; num <=50100; num++){
		bool f = false;
		for(int i=0; i<ptr; i++){
			if(prime[i]*prime[i]>num){
				break;
			}
			if(num%prime[i]==0){
				f = true;
				break;
			}
		}
		if(!f){
			prime[ptr++] = num;
		}
	}
	int n;
	while(cin>>n){
		int i=0;
		while(prime[i]<=n){
			i++;
		}
		if(prime[i-1]==n){
			printf("%d %d\n",prime[i-2],prime[i]);
		}else{
			printf("%d %d\n",prime[i-1],prime[i]);
		}
	}
	return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
 
using namespace std;
 
const double eps=1e-10;

int main()
{

	vector<int> prime;
	prime.push_back(2);
	prime.push_back(3);
	prime.push_back(5);

	for(int i=7;i<=60000;i+=2){
		bool ok=true;
		for(int j=0;prime[j]*prime[j]<=i && ok;j++){
			if(i%prime[j]==0) ok=false;
		}
		if(ok) prime.push_back(i);
//		if(ok) cout<<i<<endl;
	}

	int n;
	while(cin>>n){

		auto l=lower_bound(prime.begin(),prime.end(),n);
		auto u=upper_bound(prime.begin(),prime.end(),n);

		if(*l == n) l--;

		cout<<*l<<" "<<*u<<endl;

	}


	return 0;
}

C++: #include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>

using namespace std;

#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) REP(i, 0, n)
#define lengthof(x) (sizeof(x) / sizeof(*(x)))
#define FILL(ptr, value) FILL_((ptr), sizeof(ptr)/sizeof(value), (value))
template <typename T>
void FILL_(void * ptr, size_t size, T value){
  std::fill((T*)ptr, (T*)ptr+size, value);
}
//4方向ベクトル→↑←↓
int dx[] ={1,0,-1,0};
int dy[] ={0,-1,0,1};
bool prime[50001];
int main()
{
  for(int i = 2;i <50001;i++){
    prime[i] = true;
  }
  prime[0] = false;
  prime[1] = false;
  for(int j = 2;j*j <50001;j++){
    if(prime[j]){
      for(int i =2*j;i <50001;i+=j){
	prime[i] = false;
      }
    }
  }
  int x;
  
  while(cin>>x){
 
    for(int i = x-1;i >1;i--){
      if(prime[i]){
	cout << i <<" ";
	break;
      }
    }
    for(int i = x+1;i <50001;i++){
      if(prime[i]){
	cout << i <<endl;
	break;
      }
    }
  }
  return 0;
}

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

int main(){
	bool dt[51001];
	dt[0]=false;dt[1]=false;dt[2]=true;
	int count=0;
	for(int i=3;i<51001;i++){
		for(int j=2;j<i && j<5000;j++){
			if(dt[j]==true){if(i%j==0)count++;}
		}
		if(count==0){dt[i]=true;}else{dt[i]=false;}
		count=0;
	}
	int n=0;
	while(cin>>n){
		int i=0;
		int ansf=0,ansl=0;
		for(i=1;i<n;i++){
			if(dt[i]==true){ansf=i;}
		}
		i++;
		while(i>0){
			if(dt[i]==true){ansl=i;i=-10;}
			i++;
		}
		cout<<ansf<<" "<<ansl<<endl;
	}
	return 0;
}

C++: #include <iostream>
#include <cmath>
using namespace std;
bool flag[10000001];

int main(){
    int n=0,ans=0,ana=0;
	for(int i=0;i <= 1000000;i++){
		if(i<=1)flag[i]=false;
		else flag[i]=true;
	}
	for(int i=2;i <= 1001 ;i++){
		if(flag[i]==true){
			for(int j=i*2 ; j<=1000000 ; j=j+i){
				flag[j] = false;
			}
		}
	}
    while(cin>>n){
		ans=0,ana=0;
		for(int i=n+1;;i++){
			if(flag[i]==true){
				ans=i;
				break;
			}
		}
		for(int i=n-1;;i--){
			if(flag[i]==true){
				ana=i;
				break;
			}
		}
		cout<<ana<<" "<<ans<<endl;
	}
	return 0;
}