OFFSET
1,1
COMMENTS
Happy numbers that are prime and if the digits are reversed they remain prime (and of course happy, since addition is commutative).
This is to A031161 (palindromic lucky numbers) as prime happy numbers are to lucky numbers (A000959). - Jonathan Vos Post, Mar 16 2013
MATHEMATICA
revpQ[n_] := PrimeQ[n] && PrimeQ[FromDigits@Reverse@IntegerDigits@n]; happyQ[n_] := Block[{w = n}, While[w > 6, w = Total[ IntegerDigits[w]^2]]; w == 1]; Select[Range[10^4], revpQ[#] && happyQ[#] &] (* Giovanni Resta, Mar 16 2013 *)
PROG
(C)
int main()
{long unsigned int n, i, si, a[]={4, 16, 37, 58, 89, 145, 42, 20}, t, x, c1=0, sod(long unsigned int), rev(long unsigned int), prim(long unsigned int);
for(n=2; n<=12000; n++) {t=n; si=0; while(si!=1){for(i=0; i<=7; i++){if(t==a[i]){si=1; break; }}
if(t==1){si=1; if(prim(n)==0){x=rev(n); if(prim(x)==0){printf(", %lu", n); c1=c1+1; }}}t=sod(t); }}}
long unsigned int sod(long unsigned int m){long unsigned int d=0, r; while(m>0){r=m%10; d=d+r*r; m=m/10; } return(d); }
long unsigned int rev(long unsigned int p){long unsigned int d=0, r; while(p>0){r=p%10; d=d*10+r; p=p/10; }return(d); }
long unsigned int prim(long unsigned int n){long unsigned int i, d=0; for(i=2; i<=n/2; i++){if(n%i==0){d=1; break; }}return(d); }
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Jayanta Basu, Mar 16 2013
STATUS
approved