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>
#include <math.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(void){

  int n;
  int max_prime;
  int min_prime;

  while(cin >> n){
 
    for(int i=n-1;i>1;i--){
      if(IsPrime(i)){
	max_prime=i;
	break;
      }
    }

    for(int j=n+1;j<100000;j++){
      if(IsPrime(j)){
	min_prime=j;
	break;
      }
    }

    cout << max_prime << " " << min_prime << endl;

  }
  
  return 0;
}

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

int main(void){
  bool prime[MAX] = false;

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

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

  return 0;
}

C++: #include<bits/stdc++.h>

using namespace std;

int main(){

  vector<int> arr(80000);

  for(int i=0;i<80000;++i)
	arr[i] = 1;

  for(int i=2;i<sqrt(80000);++i){
	if(arr[i]){
	  for(int j = 0;i*(j+2) < 80000; j++)
		arr[i*(j+2)] = 0;
	}
  }

  int n;
  
  while(cin>>n){
	
	for(int i=n-1;i>=0;--i){
	  if(arr[i]==1){
		cout<<i<<" ";
		break;
	  }
  }

	for(int i=n+1;i<=80000;++i){
	  if(arr[i]==1){
		cout<<i<<endl;
		break;
	  }
	}
	
  }	
}

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

int main(){
  int n;
  while(cin >> n,n){
    int max=0;
    for(int i=1; i<n; ++i){
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%j==0){frg=false; break;}
      }
      if(frg && max<i){max=i;}
    }
    cout << max << " ";
    for(int i=n+1; i<2*n; ++i){
      bool frg = true;
      for(int j=2; j*j<i; ++j){
        if(i%j==0){frg=false; break;}
      }
      if(frg){cout << i << endl;break;}
    }
  }
  return 0;
}

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

const int NUM_MAX = 50000;

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

int getPrimeOverMin(int value){
	if((value & 0x00000001) == 0x00000000){
		++value;
	}
	for(int i=value+2; i>0; i+=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}

int getPrimeUnderMax(int value){
	if((value & 0x00000001) == 0x00000000){
		--value;
	}
	if(value==3)return 2;

	for(int i=value-2; i>2; i-=2){
		if(isPrime(i)){
			return i;
		}
	}
	return 0;
}


//0044
int main(){
	int n;
	
	while(cin >> n){
		cout << getPrimeUnderMax(n) << " " << getPrimeOverMin(n) << endl;
	}
	return 0;	
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
bool isPrime(int n){
	if(n<=1 || (n&1)==0&&n!=2)return false;
	for(int i=3;i*i<=n;i+=2)
		if(n%i==0)return false;
	return true;
}
int main(){
	vector<int> prime;
	for(int i=2;;i++){
		if(isPrime(i)){
			prime.push_back(i);
			if(50000<i)break;
		}
	}
	int n,index;
	while(cin>>n){
		index = lower_bound(prime.begin(),prime.end(),n)-prime.begin();
		if(n==prime[index])cout<<prime[index-1]<<' '<<prime[index+1]<<endl;
		else cout<<prime[index-1]<<' '<<prime[index]<<endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

using db = double;
using ll = long long;
using vi = vector <int>;
#define op operator
#define pb push_back

const int N = 6e4L + 11;
int p[N];

int main() {
	iota(p, p + N, 0);
	for(int i = 2; i < N; i ++) if(p[i] == i)
		for(int j = i; j < N; j += i) p[j] = i;
	ios :: sync_with_stdio(0);

	for(int x; cin >> x; ) {
		for(int i = x - 1; ; i --)
			if(p[i] == i) {
				cout << i << ' ';
				break;
			}
		for(int i = x + 1; ; i ++)
			if(p[i] == i) {
				cout << i << ' ';
				break;
			}
	}

	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
int INF = 1e9+7;
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for(auto i = (c).begin(); i != (c).end(); i++)
#define rep(i,b) for(auto i=0;i<(b);i++)
#define pb push_back
#define sz(c) int((c).size())

const int MAX_N = 50100;
vector<bool> primes(MAX_N, false);

void build()
{
  primes[2] = true;
  for (int i = 3; i*i <= MAX_N; i += 2) {
    if (primes[i]) {
      for (int j = 2; i*j < MAX_N; j++) {
        primes[i*j] = false;
      }
    }
  }
}

int lessthan(int n)
{
  for (int i = n - 1; i > 0; i--) {
    if (primes[i])
      return i;
  }
  return 2;
}

int morethan(int n)
{
  for (int i = n + 1; i < MAX_N; i++) {
    if (primes[i])
      return i;
  }
  return 50021;
}

int main(int argc, char **argv)
{
  for (int i = 3; i < MAX_N; i += 2) {
    primes[i] = true;
  }
  build();
  int n;
  while (cin >> n) {
    cout << lessthan(n) << " " << morethan(n) << endl;
  }

  return 0;
}

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

int sosuu(int i){
  if(i==1)return 0;
  else if(i==2)return 1;
  else if(i%2==0)return 0;
  for(int j=3;j*j<=i;j+=2){
    if(i%j==0)return 0;
  }
  return 1;
}

int main(){
  vector<int>::iterator p;
  vector<int> ve;
  int i=0,k,n;
  ve.clear();
  k=0;
  while(k<=50000){
    i++;
    if(sosuu(i)){
      k=i;
      ve.push_back(i);
    }
  }
  //for(int j=0;j<=100;j++)cout<<ve[i]<<endl;////////
  while(cin>>n){
    p=lower_bound(ve.begin(),ve.end(),n);
    if(*p==n)cout<<*(p-1)<<" "<<*(p+1)<<endl;
    else cout<<*(p-1)<<" "<<*p<<endl;
  }
return 0;
}

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

int main(){
  bool prime[50000];
  prime[0]=prime[1]=false;
  for(int i=2;i<50000;i++){
    prime[i]=true;
  }

  for(int i=2;i*i<50000;i++){
    if(prime[i]){
      for(int j=i*i;j<50000; j+=i){
        prime[j]=false;
      }
    }
  }

  while(true){
      int max,min,a;
      cin >> a;
      max=a+1;
      min=a-1;

      if(cin.eof())
        break;

      while(true){
        if(prime[max]){
          break;
        }else{
          max++;
        }
      }

      while(true){
        if(prime[min]){
          break;
        }else{
          min--;
        }
      }

      cout << min << " " << max << endl;
  }
  
  return 0;
}

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

const int MAX_S = 550000;
bool p[MAX_S];


void prime() {
  fill(p, p+MAX_S, true);
  p[0] = p[1] = false;
  for(int i = 2; i < MAX_S; i++) {
    if(p[i]) {
      for(int j = 2; i*j < MAX_S; j++) {
        p[i*j] = false;
      }
    }
  }
}

int main() {
  int x;
  prime();
  while(cin >> x) {
    int n = 2;
    bool b = false;
    for(int i = 3; i < MAX_S; i++) {
      if(b && n != x) {
        cout << n << endl;
        break;
      }

      if(i == x) {
        cout << n << ' ';
        b = true;
      }

      if(p[i]) n = i;
    }
  }
}