# Posted By

Nursoltan on 07/01/11

Viewed 1 times

# ch1 : Prime Palindromes

/ Published in: C++

Copy this code and paste it in your HTML
`/*  NAME : Nursoltan  PROB : pprime  LANG : C++  DATE : 01/07/11 14:35*/ #include <algorithm>#include <bitset>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <ctime>#include <sstream>#include <iostream>#include <map>#include <set>#include <stack>#include <utility>#include <queue> using namespace std; #define MAX 100#define INF INT_MAX#define eps (1e-9) #define FOR(_i,_k,_n) for(int (_i)=(_k); (_i)<(_n); (_i)++)#define FORR(_i,_k,_n) for(int (_i)=(_k); (_i)>=(_n); (_i)--)#define CLR(_x) memset((_x),0,sizeof(_x))#define SQR(_x) ((_x)*(_x))#define all(_x) _x.begin(),_x.end()#define sz(_x) sizeof(_x) #define vc vector<int>#define pb push_back#define mp make_pair#define iss istringstream#define oss ostringstream#define px first#define py second typedef long long ll;typedef pair <int,int> point;int ABS(int _x){ return _x>0?_x:-_x; } int a,b; bool isPrime(int x){     if(x<a || x>b) return 0;     FOR(i,2,sqrt(x)+2) if(x%i==0) return 0;     return 1;} int main(){    freopen("pprime.in","r",stdin);    freopen("pprime.out","w",stdout);     cin>>a>>b;     for(int d1=1; d1<10; d1+=2){      int x=d1;      if(isPrime(x)) cout<<x<<endl;    }    for(int d1=1; d1<10; d1+=2){      int x=10*d1+d1;      if(isPrime(x)) cout<<x<<endl;    }    for(int d1=1; d1<10; d1+=2) FOR(d2,0,10){      int x=100*d1+10*d2+d1;      if(isPrime(x)) cout<<x<<endl;    }    for(int d1=1; d1<10; d1+=2) FOR(d2,0,10){      int x=1000*d1+100*d2+10*d2+d1;      if(isPrime(x)) cout<<x<<endl;    }    for(int d1=1; d1<10; d1+=2) FOR(d2,0,10) FOR(d3,0,10){      int x=10000*d1+1000*d2+100*d3+10*d2+d1;      if(isPrime(x)) cout<<x<<endl;    }    for(int d1=1; d1<10; d1+=2) FOR(d2,0,10) FOR(d3,0,10){      int x=100000*d1+10000*d2+1000*d3+100*d3+10*d2+d1;      if(isPrime(x)) cout<<x<<endl;    }     for(int d1=1; d1<10; d1+=2) FOR(d2,0,10) FOR(d3,0,10) FOR(d4,0,10){      int x=1000000*d1+100000*d2+10000*d3+1000*d4+100*d3+10*d2+d1;      if(isPrime(x)) cout<<x<<endl;    }    for(int d1=1; d1<10; d1+=2) FOR(d2,0,10) FOR(d3,0,10) FOR(d4,0,10){      int x=10000000*d1+1000000*d2+100000*d3+10000*d4+1000*d4+100*d3+10*d2+d1;      if(isPrime(x)) cout<<x<<endl;    }     //system("pause");    return 0;}`