/******************************
* 2012/07/09 *
* AOJ_Volume0_0044 *
* Prime_NumberⅡ *
* crane *
*******************************/
#include<iostream>
#include<cmath>
using namespace std;
#define MAX_N 50023
bool field[MAX_N];
int prime[MAX_N];
int main(){
for(int i=2; i<MAX_N; i++){
field[i] = true;
prime[i] = 0;
}
int count = 0;
field[0] = false;
field[1] = false;
for(int i=2; i<MAX_N; i++){
if(field[i]){
prime[count] = i;
count++;
for(int j=i*2; j<MAX_N; j+=i){
field[j] = false;
}
}
}
int n;
while(cin >> n){
int a=0;
for(int i=0; i<MAX_N; i++){
if(prime[i] < n) a=prime[i];
if(n < prime[i]){
cout << a << " " << prime[i] << endl;
break;
}
}
}
return 0;
}
0 件のコメント:
コメントを投稿