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<string>
using namespace std;

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

int main() {
   
    std::string str;
    int num = 0;
    while(std::cin>>num){
        for(int i = num-1; 2 < i;i--){
        if(IsPrime(i) == true){
            printf("%d ",i);
            break;
        }
    }
    for(int k = num+1;k < 50022; k++){
        if(IsPrime(k) == true){
            printf("%d\n",k);
            break;
        }
    }
    
    }

}

C++: #include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int main(){
	vector<int>prime;
	for(int i=2;i<=100000;i++){
		bool f=1;
		for(int j=2;j*j<=i;j++)if(i%j==0)f=0;
		if(f)prime.push_back(i);
	}
	int n;
	while(cin>>n){
	int a=0,b=0;
	for(int i=0;;i++){
		if(prime[i]>=n){b=prime[i+1];break;}
		a=max(prime[i],a);
	}
	cout<<a<<" "<<b<<endl;
	}
	return 0;
}

C++: #include <stdio.h> 
int main(void) {
  int i, prime[90000], j, n;
  for(i = 0; i < 90000; ++i) prime[i] = 1;
  for(i = 2; i < 300; ++i) if(prime[i]) {
    for(j = 2; i * j < 90000; ++j) prime[i * j] = 0;
  }
  while(scanf("%d", &n) != EOF) {
    for(i = n - 1; i >= 2; --i) {
      if(prime[i]) {
        printf("%d ", i);
        break;
      }
    }
    for(i = n + 1; i < 90000; ++i) {
      if(prime[i]) {
        printf("%d\n", i);
        break;
      }
    }
  }
  return 0; 
}

C++: #include<iostream>
#include<cmath>
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 <stdio.h>
#include <cmath>
#include <algorithm>

#define NUM 60000

int main(){
	int table[NUM],limit;

	for(int i=0; i < NUM;i++)table[i] = 1;
	table[0] = 0;

	limit = sqrt(NUM);

	for(int i=2;i<=limit;i++){
		if(table[i] == 1){
			for(int k=2*i;k < NUM; k += i){
				table[k] = 0;
			}
		}
	}

	int n;

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

C++: #include <iostream>

using namespace std;

#include<iostream>
#include<algorithm>
using namespace std;

bool p[1000100];

void erato(){
    fill(p, p+1000100, true);
    p[0] = p[1] = false;

    for(int i=0; i < 1000100; i++){
        if(!p[i]) continue;
        for(int j=i+i; j < 1000100; j += i){
            p[j] = false;
        }
    }
}

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

C++: #include<iostream>

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(prime[i-1]==n){
			if(prime[i-2]==n) cout<<prime[i-3];
			else cout<<prime[i-2];
		}
		else cout<<prime[i-1];
		
		cout<<" "<<prime[i]<<endl;
	}
	
}

C++: #include <iostream>

using namespace std;

int main(){
        bool list[100001];
        for(int i = 2; i*i <= 100000; i++){
                for(int j = 2; !list[i] && i*j <= 100000; j++){
                        list[i*j] = true;
                }   
        }   
        int n;
        while(cin >> n){ 
                int min = n;
                while(list[--min]);
                int max = n;
                while(list[++max]);
                cout << min << " " << max << endl;
        }   
}

C++: #include <stdio.h>

int isprime(int x){
  if(!(x&1)) return 0;
  
  int i;
  for(i=3;i*i<x;i+=2){
    if(!(x%i)) return 0;
  }
  return 1;
}

int main(){
  int n;
  while(scanf("%d", &n)!=EOF){
    int i;

    int bottom=2;
    for(i=n-1;i>=2;i--) if(isprime(i)) bottom = i,i=0;

    int upper=0;
    for(i=n+1;i<=60000;i++) if(isprime(i)) upper=i,i=70000;

    printf("%d %d\n", bottom, upper);
  }
}

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;
      }
    }
  }
  
  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;
}

C++: #include<iostream>
#include<math.h>

using namespace std;

int prime[50001];

void makeprimechart(void);

int main(){

  makeprimechart();

  int n, max, min;

  while(cin >> n){

    for(int i = n+1; i < 50001; i++){
      if(prime[i] == 1){
	max = i;
	break;
      }
    }
    
    for(int i = n-1; i > 1; i--){
      if(prime[i] == 1){
	min = i;
	break;
      }
    }
    
    cout << min << " " << max << endl;
  } 
  return 0;
  
}


void makeprimechart(void){

  for(int i = 0; i < 50001; i++){
    prime[i] = 1;
  }

  prime[0] = 0;
  prime[1] = 0;


  for(int i = 2; i < sqrt(50001); i++){
    if(prime[i] == 1){
      for(int j = i * 2; j < 50001; j+=i){
	prime[j] = 0;
      }
    }
  }
}

C++: #include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#define p(n) pow(n,2)
using namespace std;
int main(){
  int n,a,b;
  vector<int> v;
  bool f;
  v.push_back(2);
  for(int i=3;i<=50000;i+=2){
    f = true;
    for(int j=0;pow(v[j],2)<=i;j++){
	if(!(i%v[j])){f=false;break;}
    }
    if(f)v.push_back(i);
  }
  while(cin>>n){
    if(cin.eof())return 0;
    vector<int>::iterator it = v.begin();
    while(it!=v.end()){
      if(n<*it){
	a=(n==*(it-1))?*(it-2):*(it-1);
	b=*it;
	cout<<a<<" "<<b<<endl;
	break;
      }
      it++;
    }
  }
}

C++: #include <iostream>

using namespace std;

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

int main(int argc, char **argv)
{
	int n, s, t;
	
	while(cin >> n){
		for(int i = n-1; i >= 2; i--){
			if(prime(i) == 1){
				s = i;
				break;
			}
		}
		for(int i = n+1; i <= 50000; i++){
			if(prime(i) == 1){
				t = i;
				break;
			}
		}
		
		cout << s << " " << t << endl;
	}
	
	return 0;
}