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;

int main(){
  int n;
  while(cin >> n,n){
    int max=0;
    for(int i=1; i<n; i+=2){
      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>
#include <vector>
#include <cmath>
using namespace std;
vector<int> sosu(60000, 1);

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

int main() {
  eratos();

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

C++: #include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
set<int> primes={2,3,5,7,11,13,17,19,23,29,31,37,
                 41,43,47,53,59,61,67,71,73,79,
                 83,89,97,101,103,107,109,113,127,131,
                 137,139,149,151,157,163,167,173,179,181,
                 191,193,197,199,211,223,227};
bool isPrime(int n){
  for(int p:primes){
    if(p*p>n)return true;
    if(n%p==0)return false;
  }
  return true;
}
int main(){
  for(int i=229;i<50040;i+=2)
    if(isPrime(i))
      primes.insert(i);
  int n;
  while(cin>>n){
    auto r=primes.lower_bound(n);
    auto l=r;
    if(primes.count(n)==1){
      r++;l--;
    }
    else{
      l--;l--;
    }
    cout<<(*l)<<" "<<(*r)<<endl;
  }
}

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

int main() {

  bool sosu[60000] = {false};

  for ( int i = 2; i < 60000; i++ ) {

    if ( sosu[i] == false ) {
      for ( int j = i*2; j < 60000; j+=i ) {
	sosu[j] = true;
      }
    }

  }

  int n;

  while( cin >> n ) {
    int cnt = n-1;
    while(true) {
      if ( sosu[cnt] == false ) {
	break;
      }
      cnt--;
    }
    n++;
    while(true) {
      if ( sosu[n] == false ) {
	cout << cnt << " " << n << endl;
	break;
      }
      n++;
    }
  }

  return 0;

}

C++: #include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
bool prime[50001];
void eratos()
{
	memset(prime,true,sizeof(prime));
	prime[0]=false;
	prime[1]=false;
	for(int i=2;i<=sqrt((double)50001)+1;i++)
	{
		if(!prime[i])continue;
		for(int j=i*2;j<50001;j+=i)
		{
			prime[j]=false;
		}
	}
	return;
}
int main()
{
	int n,k,s;
	eratos();
	while(scanf("%d",&n)!=EOF)
	{
		for(int i=n-1;;i--)
		{
			if(prime[i])
			{
				k=i;
				break;
			}
		}
		for(int i=n+1;;i++)
		{
			if(prime[i])
			{
				s=i;
				break;
			}
		}
		printf("%d %d\n",k,s);
	}
	return 0;
}

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

bool is_prime(int n){
  if(n<=1)
    return false;

  for(int i=2; i*i<=n; i++){
    if(n%i==0){
      return false;
    }
  }

  return true;
}


int main(){
  while(true){
    int next=0;
    int prev=0;

    int n;
    cin >> n;

    if(cin.eof())
      break;

    for(int i=n+1; i<=50100; i++){
      if(is_prime(i)){
        next=i;
        break;
      }
    }
    for(int i=n-1; i>=3; i--){
      if(is_prime(i)){
        prev=i;
        break;
      }
    }

    cout << prev << ' ' << next <<endl;
  }

  return 0;
}

C++: #include <string>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#define INF 100000000
#define rep(i,a) for(int i=0;i<(a);i++)

using namespace std;
typedef long long ll;

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

int main(){
    int n;
    while(cin>>n){
        for(int i=n-1;i>=2;i--){
            if(isPrime(i)){
                cout<<i<<" ";
                break;
            }
        }
        for(int i=n+1;i<100000;i++){
            if(isPrime(i)){
                cout<<i<<endl;
                break;
            }
        }
    }
    return 0;
}

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

int main() {
	int n;
	while (cin >> n) {
		int max_num = 0;
		for (int i = n - 1;; i--) {
			if (i <= 3) {
				if (i == 2 || i == 3) max_num = i;
				continue;
			}
			else {
				if (i % 2 == 0 || i % 3 == 0) continue;
				if (i % 6 != 1 && i % 6 != 5) continue;
				bool check = true;
				for (int j = 5; j * j < i; j += 6) {
					if (i % j == 0) check = false;
					if (i % (j + 2) == 0) check = false;
					if (check == false) break;
				}
				if (check == true) max_num = i;
			}
			if (max_num != 0) break;
		}
		int new_num = 0;
		for (int i = n + 1;; i++) {
			if (i <= 3) {
				if (i == 2 || i == 3) new_num = i;
				continue;
			}
			else {
				if (i % 2 == 0 || i % 3 == 0) continue;
				if (i % 6 != 1 && i % 6 != 5) continue;
				bool check = true;
				for (int j = 5; j * j < i; j += 6) {
					if (i % j == 0) check = false;
					if (i % (j + 2) == 0) check = false;
					if (check == false) break;
				}
				if (check == true) new_num = i;
			}
			if (new_num != 0) break;
		}
		cout << max_num << " " << new_num << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <set>
using namespace std;
bool p[50100];
int main()
{
  int i,j;
  set<int> s;
  for(i=2;i<50100;i++){
    if(!p[i]){
      s.insert(i);
      for(j=i*2;j<50100;j+=i){
	p[j] = true;
      }
    }
  }
  while(cin >> i,i){
    set<int>::iterator it = s.upper_bound(i);
    while(*it >= i) it--;
    cout << *it << " " << *(s.upper_bound(i)) << 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;
      }
      return 0;
}

C++: #include <iostream>
#include <stdio.h>
using namespace std;
int pr[50050];
int main() {
  int i,j,k=0,n;
  for (i=2;i<50050;i++) if (pr[i]==0) { pr[i]=1; for (j=i+i;j<50050;j+=i) pr[j]=2;}
  while(cin >> n) {
	  for (i=n-1;i>1;i--) if (pr[i]==1) { cout << i << ' '; break;}
	  for (i=n+1;i<50050;i++) if (pr[i]==1) { cout << i << endl; break;}
  }
  return 0;
}