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 <algorithm>
#include <vector>
#include <numeric>
using namespace std;


vector<int> prime;


void sieve(){
	prime.resize(100000);
	iota(prime.begin(), prime.end(), 2);
	for (int i = 0;prime[i]*prime[i] <= 100000;i++){
		prime.erase(remove_if(prime.begin() + (i + 1), prime.end(), [=](int v){ return (v%prime[i] == 0); }), prime.end());
	}
}


int main(){
	int n;
	sieve();
	while (cin >> n){
		cout << *(upper_bound(prime.begin(), prime.end(), n) - 2) << ' ' << *(upper_bound(prime.begin(), prime.end(), n)) << endl;
	}

	return 0;
}

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


#define N 50000

int main(){
    int n;

    bool is_prime[N];
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<N;i++){
      is_prime[i] = true;
    }
    for(int i=2; i*i<N; i++){
      if(is_prime[i]){
        for(int j=i*i;j<N; j+=i){
          is_prime[j] = false;
        }
      }
    }


    while(1){
      int counter = 0;
      cin >> n;
      if(n == 0)
        break;
      if(cin.eof())
        break;
      int i=0;
      while(i <= n/2){
        if(is_prime[n-i] && is_prime[n])
          counter++;
        i++;
        }
        cout << counter << endl;
      }
      retrurn 0;
}

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

int main(){
	bool prime[60000] = {};
	for (int i = 2; i < 60000; i++){
		if (prime[i]) continue;
		for (int j = 2; i * j < 60000; j++){
			prime[i * j] = true;
		}
	}
	int n, situ[2] = { -1, 1 };
	while (cin >> n){
		for (int i = 0; i < 2; i++){
			for (int j = 1;; j++){
				if (!prime[n + situ[i] * j]){
					printf("%d", n + situ[i] * j);
					if (i == 0) printf(" ");
					break;
				}
			}
		}
		puts("");
	}
	return 0;
}

C++: #include <cstdio>

using namespace std;

const int MAX_SIEVE = 60001;

bool sieve[MAX_SIEVE] = {true, true};

int main()
{
	for (int i = 2; i * i < MAX_SIEVE; i++){
		if (sieve[i]) continue;
		for (int j = i * i; j < MAX_SIEVE; j += i) sieve[j] = true;
	}
	int n;
	while (~scanf("%d", &n)){
		int mini, maxi;
		mini = maxi = n;
		while (sieve[--mini]);
		while (sieve[++maxi]);
		printf("%d %d\n", mini, maxi);
	}
	return 0;
}

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

int isprime[50101];

int main() {
  memset(isprime, 0, sizeof(isprime));
  for(int i=4; i<50101; i+=2) isprime[i] = 1;
  isprime[1] = 1;
  for(int i=3; i*i<50101; i+=2)
    if(isprime[i] == 0)
      for(int j=2; i*j<50101; ++j)
	isprime[i*j] = 1;

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

    for(int k=n+1; k<50101; ++k)
      if(isprime[k] == 0) {
	cout<<k<<endl;
	break;
      }
  }
}

C++: #include <stdio.h>

int a[2000000];

int main(){
	int n;
	for(int i = 0; i < 2000000; i++){
		a[i] = 1;
	}
	for(int i = 2; i < 2000000; i++){
		if(a[i]){
			for(int j = i * 2;j < 2000000; j = j + i){
					a[j] = 0;
			}
		}
	}

	while(scanf("%d",&n) != EOF){
		for(int i = n - 1; i > 1; i--){
			if(a[i]){
				printf("%d ",i);
				break;
			}
		}
		for(int i = n + 1; i < 2000000; i++){
			if(a[i]){
				printf("%d\n",i);
				break;
			}
		}
	}
	return 0;
}

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

int main(){
	int prime[50000];
	int ptr=0;
	unsigned long counter = 0;
	prime[ptr++] = 2;
	prime[ptr++] = 3;
	
	for(int no =3 ; no <= 50000 ; no += 2){
		int flag=0;
		for(int i=1 ; prime[i] * prime[i] <= no ; i++){
			counter++;
			if(no % prime[i] == 0){
				flag = 1;
				break; 
			}
		}
		if(!flag)
			prime[ptr++] = no;
	}
	
	int n;
	while(cin>>n){
		int i;
		for(i=0;i<50000;i++){
			if(n<prime[i])break;
		}
		if(n==3){
			cout<<2;	
		}else{
			if(prime[i-1]==n)cout<<prime[i-2];
			else cout<<prime[i-1];
		}
		//printf("%d %d",prime[i-1],prime[i-2]);
		cout<<" "<<prime[i]<<endl;
	}
	
}

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

bool Judge_Prime_Number( int x )
{
    for( int i = 2; i <= sqrt(x); i++ )
    {
        if( x % i == 0 )
            return false;
    }
    return true;
}

int main()
{
    int a;

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

        while( Judge_Prime_Number(min) == false )
            min--;
        while( Judge_Prime_Number(max) == false )
            max++;
        
        cout << min << " " << max << endl;
    }

    return 0;
}

C++: #include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

void makePrimeNumber(int N, vector<bool>& prime) // 0ツ暗按湘」Nツ暗按可コツづ個青ョツ青板つゥツづァツ素ツ青板づーツ探ツつキ
{
    prime.assign(N+1, true);
    prime [0] = prime[1] = false;
    for(int i=2; i*i<=N; i++){
        if(prime[i]){
            for(int j=i; i*j<=N; j++){
                prime[i*j] = false;
            }
        }
    }
}

int main()
{
    vector<bool> prime;
    makePrimeNumber(60000, prime);

    vector<int> num;
    for(int i=0; i<=60000; ++i){
        if(prime[i])
            num.push_back(i);
    }

    for(;;){
        int n;
        if(!(cin >> n))
            return 0;

        vector<int>::iterator it = upper_bound(num.begin(), num.end(), n);
        int tmp = *it;
        -- it;
        if(*it == n)
            -- it;
        cout << (*it) << ' ' << tmp << endl;
    }
}

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

using namespace std;

int main(){
  int n;

  while(cin>>n){
    int ans_mi,ans_ma;
    int mi_n = n-1;
    int ma_n = n+1;
    int c_mi = 0;
    int c_ma = 0;

    if(ma_n % 2 == 0){
        ++ma_n;
    }
    for(int i = ma_n; ;i = i + 2){
      int q = sqrt(i);

      if(q < 3){
        ans_mi = q;
        break;
      }
        
      else{
        c_ma = 1;
        for(int j = 3;j <= q;j = j + 2){
          if(i % j == 0){
            c_ma = 0;
            break;
          }
        }
        if(c_ma == 1){
          ans_ma = i;
        }
      }
    }


    if(mi_n == 2){
      ans_mi = 2;
    }
    else{
      if(mi_n % 2 == 0){
        --mi_n;
      }
      for(int i = mi_n;i > 2;i = i - 2){
        int q = sqrt(i);

        if(q < 3){
          ans_mi = q;
          break;
        }
        else{
          c_mi = 1;
          for(int j = 3;j <= q;j = j + 2){
            if(i % j == 0){
              c_mi = 0;
              break;
            }
          }
          if(c_mi == 1){
            ans_mi = i;
          }
        }
      }
    }
  }
  return 0;
}

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

int main(){
	int n[1000000]={0};
	int x, s, l;
	
	for(int i=1; i<=999999; i++){
		if(i==1) n[i]=-1;
		else if(n[i]==0){
			for(int k=2; k*i<=999999; k++){
				n[k*i]=-1;
			}
		}
	}
	
	while(cin>>x){
		for(int j=x-1;; j--){
			if(n[j]==0){s=j; break;}
		}

		for(int o=x+1;; o++){
			if(n[o]==0) {l=o; break;}
		}
		cout << s << " " << l << endl;
	}
	
	return 0;
}