|
|
A073902
|
|
Number of n-digit primes with digit sum n.
|
|
0
|
|
|
0, 1, 0, 4, 12, 0, 95, 212, 0, 2395, 10657, 0, 126068, 375941, 0, 4943357, 20513691, 0, 271911476
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,4
|
|
COMMENTS
|
|
|
LINKS
|
|
|
EXAMPLE
|
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.
|
|
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 *)
|
|
PROG
|
(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
|
|
CROSSREFS
|
|
|
KEYWORD
|
base,nonn
|
|
AUTHOR
|
|
|
EXTENSIONS
|
a(4) and a(5) corrected, and example corrected, by Harvey P. Dale, Aug 09 2011
|
|
STATUS
|
approved
|
|
|
|