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<cstdio>
using namespace std;
int main(void){
  int i,no,input;
  int prime[500];
  int ptr=0,c=0;
  int flag=0;
  int last;
  
  while(cin>>input){
    flag=ptr=c=0;
    prime[ptr++]=2;
    prime[ptr++]=3;
    for(no=5;no<=10000;no+=2){
      if(flag==2){break;}
      if(input+1<=no){flag=1;c++;}
      if(c==1){if(input==prime[ptr-1])last =ptr-2;else last=ptr-1;}
      for(i=1;i<ptr;i++){
	if(no%prime[i]==0)break;
      }
      if(ptr==i){
	prime[ptr++]=no;
	if(flag==1){flag=2;}
      }
    }
    
    printf("%d %d\n",prime[last],prime[ptr-1]);
  }
    return 0;
}

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

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

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

C++: using System;
using System.Collections.Generic;

namespace _0044
{
    class Programｓ
    {
        static void Main(string[] args)
        {
            List<int> primeList = new List<int>();
            for (int i = 1; i < 50022; i++)
            {
                if (IsPrime(i))
                {
                    primeList.Add(i);
                }
            }

            while (true)
            {
                var input = Console.ReadLine();
                if (string.IsNullOrEmpty(input)) { break; }
                int number = int.Parse(input);
                int previousPrimeNumber = 0;
                int nextPrimeNumber = 0;

                foreach (var primeNumber in primeList)
                {
                    if (primeNumber < number)
                    {
                        previousPrimeNumber = primeNumber;
                    }
                    else if (primeNumber > number)
                    {
                        nextPrimeNumber = primeNumber;
                    }

                    if (nextPrimeNumber != 0)
                    {
                        break;
                    }
                }
                Console.WriteLine("{0} {1}", previousPrimeNumber, nextPrimeNumber);
            }
        }

        static bool IsPrime(int number)
        {
            if (number <= 1)
            {
                return false;
            }
            else if (number <= 3)
            {
                return true;
            }
            else if ((number % 2) == 0)
            {
                return false;
            }
            else
            {
                for (int i = 3; i <= (int)Math.Sqrt(number); i += 2)
                {
                    if (number % i == 0)
                    {
                        return false;
                    }
                }
            }
            return true;
        }
    }
}

C++: #include<iostream>
using namespace std;
int main(){
  int n,sans,lans,nk,count=0;
  while(cin>>n){
    nk = n;
    for(int i=nk-1;i>=2;i--){
      for(int j=1;j<=i;j++){
	if(i%j==0) count++;
      }
      if(count==2){
	cout << i << ' ';
	count = 0;
	break;
      }
      else count = 0;
    }
    for(int i=nk+1;i<=50021;i++){
      for(int j=1;j<=i;j++){
	if(i%j==0) count++;
      }
      if(count==2){
	cout << i << endl;
	count = 0;
	break;
      }
      else count = 0;
    }
  }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int prime[55002];
  prime[0] = prime[1] = 0;
  for(int i = 2 ; i < 55001 ; i++)prime[i] = 1;

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

  int n;
  while(cin >> n){
    int ans_M,ans_m;

    for(int i = n-1 ;; i-- ){
      if(prime[i]){
	ans_m = i;break;
      }
    }
    for(int i = n+1 ;; i++ ){
      if(prime[i]){
	ans_M = i;break;
      }
    }
    cout << ans_m<<" "<<ans_M<<endl;

  }
}

C++: #include<iostream>
#include<set>
using namespace std;
set<int>data;
int main(){
	data.insert(2);
	for(int i=3;i<60000;i++){
		for(int j=2;j*j<=i;j++){
			if(i%j==0)goto fail;
		}
		data.insert(i);
		fail:;
	}
	
	int x;
	while(cin>>x){
		set<int>::iterator itr=data.lower_bound(x);
		cout<<*(--itr)<<" ";
		if(*(++itr)==x)itr++;
		cout<<*itr<<endl;
	}
}

C++: #include<iostream>
#include<vector>
#define MAX 1000000
using namespace std;
int main(){
    vector<bool> v(MAX);
    for(int i = 0;i<MAX;i++)
      v[i]=true;

      v[0]=v[1]=false;
    for(int i = 2;i<1000;i++){
      if(v[i]){
        for(int j=i*i;j<MAX;j+=i){
         v[j]=false;
       }
      }
    }
    while(true){
      int a;
      cin >> a;
      if(cin.eof())return 0;
      while(int i=a-1){
        if(v[i]){
          cout <<i<<' ';
          break;
      }
      i--;
    }
    while(int i=a+1){
      if(v[i]){
        cout <<i<<endl;
        break;
     }
    i++;
   }
 }
}

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

int prime[MAX];

void p(void){
  int num = 0,judge[MAX] = {0};
  judge[0] = judge[1] = 1;
  for(int i = 2 ; i*i < MAX ; i++){
    if(judge[i] == 0){
      for(int j = i*2 ; j < MAX ; j += i){
        judge[j] = 1;
      }
    }
  }
  
  for(int i = 2 ; i < MAX ; i++){
    if(judge[i] == 0) prime[num++] = i;
  }
}

int main(void){
  int n;

  p();
  while(cin >> n){
    int key = 0;
    while(1){
      if(n == prime[key]){
        cout << prime[key-1] << ' ' << prime[key+1] << endl;
        break;  
      }
      else key++;
    }
  }

  return 0;
}

C++: #include <iostream>

using namespace std;

const int MAX_P = 50001;
bool p[MAX_P];  // prime table

void init()
{
    for (int i = 0; i < MAX_P; i++)
        p[i] = true;

    p[0] = p[1] = false;
    for (int i = 2; i * i < MAX_P; i++) {
        if (p[i]) {
            for (int j = i * 2; j < MAX_P; j += i)
                p[j] = false;
        }
    }
}

int main()
{
    int n;

    init();

    while (cin >> n) {
        int min, max;

        min = max = n;
        while (--min >= 2) 
            if (p[min])
                break;
        while (++max <= MAX_P) 
            if (p[max])
                break;

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

    return 0;
}