#include<stdio.h> #include<stdlib.h> #include<iostream> #include<math.h> using namespace std; const int maxn=10010; int prime[maxn]; bool p[maxn]; int pNum=0; void Find_Prime() { for(int i=2;i<maxn;i++) { if(p[i]==false) { prime[pNum++]=i; for(int j=i+i;j<maxn;j+=i) { p[j]=true; } } } } int isHuiWen(int n) { int b=n; int a; int sum=0; int len=(int)log10(n)+1; int c=len; // printf("%d",len); //取末尾再组装 for(int i=0;i<c;i++) { a=n%10; sum+=a*pow(10,len-1); len--; n=n/10; //printf("a=%d,n=%d\n",a,n); } //printf("%d\n",sum); if(sum==b) return 1; else return 0; } int main() { p[0]=true; p[1]=true; Find_Prime(); int a,b; cin>>a>>b; int count=0; for(int i=a;i<=b;i++) { if(p[i]==false&&isHuiWen(i)) { count++; printf("%6d",i); if((count)%5==0) printf("\n"); } } system("pause"); } |
Double click to view unformatted code.