View Code of Problem 92

#include <bits/stdc++.h>
using namespace std;

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

bool isHW(int n) {
    int t,k=n,sum=0;
    while(k>0) {
        t=k%10;
        k=k/10;
        sum=sum*10+t;
    }
    if(sum==n)  return true;
    else return false;
}

int main() {
    int a,b,i,j;
    scanf("%d%d",&a,&b);
    int num[1000],cnt=0;
    for(i=a; i<=b; i++) {
        if(isPrime(i)&&isHW(i)) {
            num[cnt++]=i;
        }
    }
    for(i=0; i<cnt; i++) {
        printf("%6d",num[i]);
        if((i+1)%5==0)  printf("\n");
    }
    return 0;
}

Double click to view unformatted code.


Back to problem 92