打表法
#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
bool zi(int a) {
int n=sqrt(a);
for(int i=2; i<=n; i++) {
if(a%i==0) return false;
}
return true;
}
bool hui(int b) {
int z[9]= {0};
int n=0;
int a=b;
while(a!=0) {
z[n]=a%10;
a/=10;
n++;
}
if(b!=11&&n%2==0) return false;
for(int i=0; i<n/2; i++) {
if(z[i]!=z[n-1-i]) return false;
}
return true;
}
void huizi(int a,int b) {
if(a%2==0) a+=1;
for(int i=a; i<=b; i+=2) {
if(hui(i)&zi(i)){
cout<<i<<endl;
}
}
cout<<-1;
}
int main() {
FILE *fp=freopen("h.txt","w",stdout);
huizi(5,10000000);
fclose(stdout);
int a,b;
fflush(fp);//将输出缓冲区清空
freopen( "CON","w",stdout);//恢复标准输出文件描述符
cin>>a>>b;
if(b>10000000) b=10000000;
freopen("h.txt","r",stdin);
int t=a;
while(t>=a&&t<=b) {
cin>>t;
if(t==-1) break;
cout<<t<<endl;
}
fclose(stdin);
return 0;
}

浙公网安备 33010602011771号