login

Reminder: The OEIS is hiring a new managing editor, and the application deadline is January 26.

Palindromes with exactly 2 prime factors (counted with multiplicity).
15

%I #48 Aug 15 2022 05:14:09

%S 4,6,9,22,33,55,77,111,121,141,161,202,262,303,323,393,454,505,515,

%T 535,545,565,626,707,717,737,767,818,838,878,898,939,949,959,979,989,

%U 1111,1441,1661,1991,3113,3223,3443,3883,7117,7447,7997,9119,9229,9449,10001

%N Palindromes with exactly 2 prime factors (counted with multiplicity).

%H Giovanni Resta, <a href="/A046328/b046328.txt">Table of n, a(n) for n = 1..10000</a> (first 2000 terms from Zak Seidov, terms a(2001)-a(2816) from Michael De Vlieger)

%e 111 is a palindrome and 111 = 3*37. 3 and 37 are primes.

%t fQ[n_] := Block[{id = IntegerDigits[n]}, Plus @@ Last /@ FactorInteger[n] == 2 && id == Reverse[id]]; Select[ Range[ 10000], fQ[ # ] &] (* _Robert G. Wilson v_, Jun 06 2005 *)

%t Select[Range[10002], Reverse[x = IntegerDigits[#]] == x && PrimeOmega[#] == 2 &] (* _Jayanta Basu_, Jun 23 2013 *)

%t Select[Range[11000],PalindromeQ[#]&&PrimeOmega[#]==2&] (* Requires Mathematica version 10 or later *) (* _Harvey P. Dale_, Apr 30 2018 *)

%o (PARI) ispal(n) = my(d=digits(n));d == Vecrev(d) \\ A002113

%o for(k=1,1e4,if(ispal(k)&&bigomega(k)==2, print1(k, ", "))) \\ _Alexandru Petrescu_, Jul 07 2022

%o (Python)

%o from sympy import factorint

%o from itertools import product

%o def ispal(n): s = str(n); return s == s[::-1]

%o def pals(d, base=10): # all d-digit palindromes

%o digits = "".join(str(i) for i in range(base))

%o for p in product(digits, repeat=d//2):

%o if d > 1 and p[0] == "0": continue

%o left = "".join(p); right = left[::-1]

%o for mid in [[""], digits][d%2]: yield int(left + mid + right)

%o def ok(pal): return sum(factorint(pal).values()) == 2

%o print(list(filter(ok, (p for d in range(1, 6) for p in pals(d) if ok(p))))) # _Michael S. Branicky_, Aug 14 2022

%Y Cf. A046315, A046408, A108505.

%Y Subsequence of A001358 and A046338.

%K nonn,base

%O 1,1

%A _Patrick De Geest_, Jun 15 1998