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

bool is_prime[100001];

void eratos(int N) {
  is_prime[0] = false, is_prime[1] = false;
  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;
      }
    }
  }
}

int main() {
  for (int i = 0; i <= 100000; ++i) {
    is_prime[i] = true;
  }
  eratos(100000);

  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 <= 100000; ++i) {
      if (is_prime[i]) {
        cout << i << endl;
        break;
      }
    }
  }
}

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

const int MX = 10000000;
bool sieve[MX];

int main() {
    memset(sieve, false, sizeof sieve);
    sieve[0] = sieve[1] = true;
    for (int i=2; i*i<MX; ++i) {
        if ( ! sieve[i]) {
            for (int j=i*i; j<MX; j+=i) {
                sieve[j] = true;
            }
        }
    }
    int n;
    while (cin >> n) {
        int l, h;
        for (int i=n-1; ; --i) {
            if ( ! sieve[i]) {
                l = i; break;
            }
        }
        for (int i=n+1; ; ++i) {
            if ( ! sieve[i]) {
                h = i; break;
            }
        }
        cout << l << " " << h << endl;
    }
    return 0;
}

C++: #include <stdio.h>
int main(){
int n,i,f[10000],now=2;
bool flag;
f[0]=2;
f[1]=3;
for(i=5;i<50000;i+=2){
flag=true;
for(int j=1;f[j]*f[j]<=i&&flag;j++){
if(i%f[j]==0)flag=false;
}
if(flag){
f[now]=i;
now++;
}
}
while(scanf("%d",&n)!=EOF){
for(i=0;f[i]<n;i++);
printf("%d %d\n",f[i-1],f[i]);
}
}

C++: #include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
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 j=0;
       while(prime[j]<=n){
           j++;
       }
       if(prime[j-1]==n){
           printf("%d %d",prime[j-2],prime[j]);
       }else{
           printf("%d %d",prime[j-1],prime[j]);
       }
       cout<<endl;
   }
   return 0;
}

C++: #include<iostream>
using namespace std;
int isPrime(int n){
  for(int i=2;i*i<=n;i++) if(n%i==0) return 0;
  return 1;
}
int main(){
  bool d[70000];
  for(int i=0;i<70000;i++) d[i]=isPrime(i);
  int n;
  while(cin >> n){
    int k=1;
    while(!d[n-k]) k++;
    cout << n-k << " ";k=1;
    while(!d[n+k]) k++;
    cout << n+k << endl;
  }
}

C++: #include <iostream>
using namespace std;
int main(){
    bool is_prime[60000];
    is_prime[0] = is_prime[1] = false;
    for(int i=2; i<60000; i++){
        is_prime[i] = true;
    }

    for(int i=2; i*i<60000; i++){
        if(is_prime[i]){
            for(int j=i*i; j<60000; j+=i){
                is_prime[j] = false;
            }
        }
    }
    while(true){
        int n;
        cin >> n;
        if(cin.eof())
            break;
        int i=n;
        while(true){
            if(is_prime[i-1]){
                cout<<i-1<<" ";
                break;
            }
            else i--;
        }
        i=n;
        while(true){
            if(is_prime[i+1]){
                cout<<i+1<<endl;
                break;
            }
            else i++;
        }
    }
    return 0;
}

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

const int SIZE = 50010;
bool isprime[SIZE + 1] = {0};
vector<int> prime;
void make_prime(){
    isprime[1] = true;
    isprime[0] = true;
    for(int i = 2; i <= SIZE; i++){
        if(isprime[i]) continue;
        for(int j = i * 2; j <= SIZE; j += i) isprime[j] = true;
        prime.push_back(i);
    }
}

int main(){
    make_prime();
    int n;
    while(cin >>n){
        int min, max;
        for(min = n - 1; isprime[min] != false; min--) ;
        for(max = n + 1; isprime[max] != false; max++) ;
        cout <<min <<" " <<max <<endl;
    }
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <cmath>
using namespace std;
vector<int> sosu(50000, 1);

void eratos() {
  for(int i = 2; i < sqrt(50000); i++) {
    if(sosu[i] == 1) {
      for(int j = 2; i*j < 50000; j++) {
	sosu[i*j] = 0;
      }
    }
  }
}

int main() {
  eratos();

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

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

using namespace std;

int main(){
  int n;

  while(cin>>n){
    int ans_ma;
    int ma_n = n + 1;
    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_ma = 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;
          break;
        }
      }
    }

    int ans_mi;
    int mi_n = n - 1;
    int c_mi = 0;

    if(mi_n == 2){
      ans_mi = 2;
    }
    else{
      if(mi_n % 2 == 0){
        --mi_n;
      }
      for(int i = mi_n;i >= 3;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;
            break;
          }
        }
      }
    }
    cout<<ans_mi<<" "<<ans_ma<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main()
{
    int num[50500],n,ma,anslow=0,anshigh=0;
    ma=sqrt(50500);
    for(int i=1;i<50500;i++)num[i]=0;
    for(int i=2;i<ma;i++){
        if(num[i]==0){
            for(int j=2;j*i<50500;j++)num[j*i]=1;
        }
    }
    while(cin>>n){
        for(int i=1;anslow==0||anshigh==0;i++){
            if(num[n-i]==0&&anslow==0)anslow=n-i;
            if(num[n+i]==0&&anshigh==0)anshigh=n+i;
        }
        cout<<anslow<<" "<<anshigh<<endl;
        anshigh=0;anslow=0;
    }
}