login
Number of n-digit primes whose digits are all odd.
2

%I #34 Jan 14 2023 08:44:48

%S 3,12,42,125,608,2427,10081,43568,197823,873432,3978580,18159630,

%T 83753054,387670103,1811802273,8451565541,39790817677

%N Number of n-digit primes whose digits are all odd.

%F a(n) = A358685(n) - A358685(n-1).

%e a(2) = 12 as there are 12 2-digit primes whose digits are all odd: 11, 13, 17, 19, 31, 37, 53, 59, 71, 73, 79, 97.

%t Length[Select[Prime[Range[PrimePi[10^(n - 1)], PrimePi[10^n]]], And @@ OddQ[IntegerDigits[#]] &]]

%o (Python)

%o from sympy import primerange

%o def a(n):

%o num=0

%o for f in range(1,10,2):

%o p=list(primerange(f*10**(n-1),(f+1)*10**(n-1)))

%o num+=sum(1 for k in p if all(int(d) %2 for d in str(k)))

%o return(num)

%o print ([a(n) for n in range(1,8)])

%o (Python)

%o from sympy import isprime

%o from itertools import count, islice, product

%o def a(n):

%o c = 0 if n > 1 else 1

%o for p in product("13579", repeat=n-1):

%o s = "".join(p)

%o for last in "1379":

%o if isprime(int(s+last)): c += 1

%o return c

%o print([a(n) for n in range(1, 10)]) # _Michael S. Branicky_, Nov 27 2022

%Y Cf. A030096, A358685.

%K base,nonn,more

%O 1,1

%A _Zhining Yang_, Nov 26 2022

%E a(10)-a(14) from _Michael S. Branicky_, Nov 26 2022

%E a(15) from _Zhining Yang_, Dec 21 2022

%E a(16)-a(17) from _Martin Ehrenstein_, Dec 24 2022