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 <cstring>

using namespace std;

int main(void){
  int prime[50000];
  int prime_f[50001];
  int k;
  int n;
  int i,j;
  int n_size;

  while(cin>>n){
    k=0;
    memset(prime_f,0,sizeof(prime_f));
    prime_f[0]=prime_f[1]=1;
    for(i=2;i<50000;i++){
      if(!prime_f[i]){
	k++;
	prime[k]=i;
	for(j=2*i;j<50000;j+=i){
	  prime_f[j]=1;
	}
      }
    }

    for(i=0;i<k;i++){
      if(prime[i]>=n){
	printf("%d %d\n",(prime[i]>=n)? prime[i-1]:prime[i],prime[i+1]);
	break;
      }  
    }
  }
  return(0);
}

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

int main(){
	long long int prime[50040];
	long long int ptr=0;
	unsigned long counter = 0;
	prime[ptr++] = 2;
	prime[ptr++] = 3;
	
	for(int no =3 ; no <= 50040 ; 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;
	}
	
	long long int n;
	while(cin>>n){
		int i;
		for(i=0;i<50040;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<bits/stdc++.h>
using namespace std;

#define MAX_N 51000

int prime[MAX_N];
bool is_prime[MAX_N + 1];


void prime_generate(){
	int p = 0;
	for(int i = 0; i <= MAX_N; i++) is_prime[i] = true;

	is_prime[0] = is_prime[1] = false;

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

void solve(int n){
	for(int i = 0; i < MAX_N; i++){
		if(prime[i] == n){
			cout << prime[i-1] << " " << prime[i+1] << endl;
			break;
		}
		else if(prime[i] > n){
			cout << prime[i-1] << " " << prime[i] << endl;
			break;
		}
		else continue;
	}
}

int main(){
	prime_generate();

	int n;
	while(cin >> n){
		solve(n);
	}
}

C++: #include <stdio.h>
#define MAX 60000
int main(void){
 	int i,j;
	int a[MAX+1];
	int n;
	int bn;
	while(scanf("%d",&n) != EOF){
		  for(i = 1; i <= MAX; i++){
			  a[i] = 0;
		  }
		  for(i = 2; i <= MAX; i++){
			  if(a[i]){continue;}
			  for(j = i; j <= MAX; j += i){
				  if(j == i){a[i] = 0;}
				  else{a[j] = 1;}
			  }
		  }
		  for(i = 2; i <= n; i++){
			if(n == i){
				printf("%d ",bn);
			} 
			  if(!a[i]){
				bn = i;	 
			  }
		  }
		  for(; a[i];i++){}
		  printf("%d\n",i);
	}
 	return 0;
}

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

int main() {
    const int MAX = 50100;
    bool isPrime[MAX];
    fill_n(isPrime, MAX, true);
    for (int i = 4; i < MAX; i += 2) {
        isPrime[i] = false;
    }
    for (int i = 3; i * i <= MAX; i += 2) {
        if (isPrime[i]) {
            for (int j = 2 * i; j < MAX; j += i) {
                isPrime[j] = false;
            }
        }
    }
    int n;
    while (cin >> n) {
        for (int i = n - 1; ; i--) {
            if (isPrime[i]) {
                cout << i << " ";
                break;
            }
        }
        for (int i = n + 1; ; i++) {
            if (isPrime[i]) {
                cout << i << endl;
                break;
            }
        }
    }
}

C++: #include <iostream>
using namespace std;
 
int main(){
  bool is_prime[100000];
 
  is_prime[0]=is_prime[1]=false;
  for(int i=2;i<100000;i++){
    is_prime[i] = true;
  }
 
  for(int i=2;i*i<100000;i++){
    if(is_prime[i]){
      for(int j=i*i;j<100000;j=j+i){
        is_prime[j] = false;
      }
    }
  }
 
  while(true){
    int n;
    cin >> n;
 
    if(cin.eof())
        break;
 
    int high = n;
    int low = n;
 
    while(1){
      high = high+1;
      if(is_prime[high]){
        break;
      }
    }
 
    while(1){
      low = low-1;
      if(is_prime[low]){
        break;
      }
    }
 
    cout << low << " " << high << endl;
  }
 
  return 0;
}

C++: #include<iostream>
using namespace std;
bool isprime(int n) {
	if (n == 2)return true;
	if (n % 2 == 0)return false;
	for (int i = 3; i <= sqrt(n); i += 2) if (n%i == 0)return false;
	return true;
}
int main() {
	int n;
	while (cin >> n){
		for (int i = n - 1; ; i--){
			if (isprime(i)) {
				cout << i << ' ';
				break;
			}
		}
		for (int i = n + 1;; i++) {
			if (isprime(i)) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

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

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

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



bool judgePrimenum(int n){

	int sqr = sqrt((double)n);

	if(n%2 == 0)return false;

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

	return true;
}




int main(){
	while(true){
		int n, min=0, max=0, i=1;
		cin >> n;

		while(min==0 || max==0){
			if( max==0 && judgePrimenum(n+i) )max=n+i;
			if( min==0 && judgePrimenum(n-i) )min=n-i;
			++i;
		}

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

C++: #include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int NUM=60000,UPTO=sqrt(NUM);
int main(){
    bool pris[NUM];
    fill(pris,pris+NUM,true);
    pris[0]=pris[1]=false;
    for(int i=2;i<=UPTO;i++){
        if(pris[i]){
            for(int j=i*i;j<NUM;j+=i){
                pris[j]=false;
            }
        }
    }
    int n;
    while(scanf("%d",&n)!=-1){
        int ll=-1,l=-1;
        for(int i=2;i<NUM;i++){
            if(pris[i]){
                if(i>n){
                    if(pris[n]) printf("%d %d\n",ll,i);
                    else printf("%d %d\n",l,i);
                    break;
                }
                ll=l;
                l=i;
            }
        }
    }
}

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

int main(){
  int table[80000]={};
  for(int i=2; i*i<80000; ++i){
    if(!table[i]){
      for(int j=i*2; j<=80000; j+=i){
        table[j]=1;
      }
    }
  }
  for(int i=0; i<100; ++i){
    if(table[i]==0){
      cout << i << " ";
    }
  }
  int n;
  while(cin >> n,n){
    int i;
    for(i=n-1; table[i]; --i);
    cout << i << " ";
    for(i=n+1; table[i]; ++i);
    cout << i << endl;
  }
  return 0;
}