A073902 Number of n-digit primes with digit sum n.
0, 1, 0, 4, 12, 0, 95, 212, 0, 2395, 10657, 0, 126068, 375941, 0, 4943357, 20513691, 0, 271911476
Offset: 1
Examples
a(2) = 1 because the only two-digit prime with digit sum 2 is 11. a(5) = 12: the primes are 10103, 10211, 10301, 11003, 12011, 12101, 13001, 20021, 20201, 21011, 21101, and 30011.
Crossrefs
Cf. A069710.
Programs
-
Mathematica
Table[Length[Select[Prime[Range[PrimePi[10^(n-1)]+1,PrimePi[10^n]]], Total[IntegerDigits[#]]==n&]],{n,8}] (* Harvey P. Dale, Aug 09 2011 *)
-
Python
from sympy import isprime def nextsod(n, base): c, b, w = 0, base, 0 while True: d = n%b if d+1 < b and c: return (n+1)*b**w + ((c-1)%(b-1)+1)*b**((c-1)//(b-1))-1 c += d; n //= b; w += 1 def a(n): if n%3 == 0: return 0 c, t = 0, 10**(n-1) + ((n-1)%9+1)*10**((n-1)//9)-1 while t < 10**n: if isprime(t): c += 1 t = nextsod(t, 10) return c print([a(n) for n in range(1, 13)]) # Michael S. Branicky, Aug 02 2022
Extensions
More terms from Sascha Kurz, Aug 23 2002
a(4) and a(5) corrected, and example corrected, by Harvey P. Dale, Aug 09 2011
a(11) corrected and a(13)-a(15) from Donovan Johnson, Aug 10 2011
a(16)-a(18) from David Radcliffe, May 05 2015
a(19) from Michael S. Branicky, Aug 02 2022
Comments