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++: //0044 Prime Number II

#include<cstdio>
#include<cmath>
using namespace std;

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

int main(void)
{
	int n;
	int i;
	while(scanf("%d", &n) == 1)
	{
		for(i = n-1; i>= 2; i--)
		{
			if(isPrime(i))
			{
				printf("%d ", i);
				break;
			}
		}
		for(i = n+1; ; i++)
		{
			if(isPrime(i))
			{
				printf("%d\n", i);
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

const int MAX = 1000100;
bool prime[MAX];

void sieve(){
	fill(prime, prime+MAX, true);
	prime[0] = prime[1] = false;

	for(int i=2; i*i < MAX; i++){
		if(!prime[i]) continue;
		for(int j=i*i; j < MAX; j += i) prime[j] = false;
	}
}


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

C++: #include <string>
#include <iostream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
 
using namespace std;

bool isP[50001];
  
int main(){
	fill(isP, isP+50001, true);
	for(int i = 2; i <= 50000; i++){
		if(isP[i]){
			for(int j = i*2; j <= 50000; j += i){
				isP[j] = false;
			}
		}
	}

	int n;

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

	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstring>
#define MAX_N 50100
using namespace std;

bool prime[MAX_N + 1];

bool isPrime(int n) {
    //今回、０、１をこの関数の引数に取らない
    for(int r = 2; r * r <= n; r++) {
        if(n % r == 0) return(false);
    }
    return(true);
}

void initialize() {
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1] = false; //0,1は素数ではない。
    for(int r = 2; r * r <= MAX_N; r++) {
        if(isPrime(r)) {
            for(int c = r * 2; c <= MAX_N; c += r) prime[c] = false; //倍数は素数で無い事が分かっている
        }
    }
}

int searchSmall(int num) {
    for(int r = num - 1; r >= 0; r--)
        if(prime[r]) return(r);
    return(-1);
}

int searchLarge(int num) {
    for(int r = num + 1; r <= MAX_N; r++)
        if(prime[r]) return(r);
    return(-1);
}

int main(void) {
    initialize();
    
    int input;
    while(cin >> input) {
        int max = searchSmall(input), min = searchLarge(input);
        cout << max << " " << min << endl;
    }
    return(0);
}

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

int n;
int check(int i)
{
    if(i==2) return 1;
    if(i%2==0) return 0;
    for(int a=3;a*a<=i;a+=2)
    {
        if(i%a==0) return 0;
    }
    return 1;
}
int solve_a()
{
    int i;
    for(i=n-1;!check(i);i--);
    return i;
}
int solve_b()
{
    int i;
    for(i=n+1;!check(i);i++);
    return i;
}
int main()
{
    while(cin >> n)
    {
        cout << solve_a() << ' ' << solve_b() << endl;
    }
}

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

int main(void)
{
	int n, min=2, max =2;

	while (cin >> n)
	{
		bool f;
		for (int i = n-1; i >= 2; i--)
		{
			if (i == 2)
			{
				max = 2;
				continue;
			}
			f = true;
			for (int j = i-1; j >= 2; j--)
			{
				if (i % j == 0)
				{
					f = false;
					break;
				}
			}
			if (f == true)
			{
				max = i;
				break;
			}
		}
		for (int i = n + 1;; i++)
		{
			f = true;
			for (int j = i-1; j >= 2; j--)
			{
				if (i % j == 0)
				{
					f = false;
					break;
				}
			}
			if (f == true)
			{
				min = i;
				break;
			}
		}
		cout << max << " " << min << endl;
	}
	return 0;
}

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

bool prime[MAX];
void calcPrime(){
	for(int i = 2; i < MAX; i++) prime[i] = true;
	for(int i = 2; i < MAX; i++){
		if( prime[i] ){
			for(int j = i+i; j <= MAX; j += i){
				prime[j] = false;
			}
		}
	}
}

int main(){
	int n;
	calcPrime();
	while( cin >> n ){
		int under = -1, over = -1;
		for(int d = n, u = n;; ){
			if( 2 < d ) d--;
			if( u < MAX ) u++;
			if( under != -1 && over != -1 ) break;
			if( prime[d] ) under = d;
			if( prime[u] ) over = u;
		}
		cout << under << " " << over << endl;
	}
}

C++: #include<iostream>
using namespace  std;
bool isPrime(int p)
{
	if (p <= 1)return false;
	for (int i = 2; i * i <= p; i++)
	{
		if (p % i == 0)return false;
	}
	return true;
}
int main()
{
	int n;

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

C++: //include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <complex>
#include <math.h>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

const long double EPS = 1e-12;
const LL INF = 1e18;




int main(){
	int N;
	vector<int>prime;
	FOR(i,2,51000){
		bool flag=true;
		for(int j=2;j*j<=i;j++)if(i%j==0)flag=false;
		if(flag)prime.PB(i);
	}
	while(cin>>N){
		vector<int>::iterator itr=upper_bound(ALL(prime),N);
		int res2=*itr;
		itr--;
		if(*itr==N)itr--;
		int res1=*itr;
		cout<<res1<<" "<<res2<<endl;
	}
	return 0;
}
/*

*/