# 某岛

… : "…アッカリ～ン . .. . " .. .
October 20, 2010

## HOJ 1004. Prime Palindromes

nimendongde ..

### Analysis:

/* This Code is Submitted by xiaodao for Problem 1004 at 2010-10-24 14:13:43 */
#include <iostream>
#include <cmath>
using namespace std;

const int N = 9999;

string s; int x;
int l, r;

string L(int x){
string res;
while (x!=0){
res = char(x%10 + 48) + res;
x /= 10;
}
return res;
}

string R(int x){
string res;
while (x!=0){
res = res + char(x%10 + 48);
x /= 10;
}
return res;
}

string M(int x){
string res; res = x + 48;
return res;
}

int g(string x){
int res = 0;
for (int i=x.size()-1;i>=0;i--)
res = res * 10 + (x[i]-48);
return res;
}

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

void Letsgo(){
for (int i=1;i<=N;i++){
for (int j=0;j<=9;j++){
x = g(L(i) + M(j) + R(i));
if (x > r) return;
if (l<=x && x<=r && isPrime(x)) cout << x << endl;
}
}
}

int main(){
while (cin >> l >> r){
if (l<=5 && 5<=r) cout << 5 << endl;
if (l<=7 && 7<=r) cout << 7 << endl;
if (l<=11 && 11<=r) cout << 11 << endl;
Letsgo();
}
}