login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A073902 Number of n-digit primes with digit sum n. 0

%I #30 Aug 02 2022 17:17:25

%S 0,1,0,4,12,0,95,212,0,2395,10657,0,126068,375941,0,4943357,20513691,

%T 0,271911476

%N Number of n-digit primes with digit sum n.

%C a(3n) = 0. - _Sascha Kurz_, Aug 23 2002

%e 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.

%t Table[Length[Select[Prime[Range[PrimePi[10^(n-1)]+1,PrimePi[10^n]]], Total[IntegerDigits[#]]==n&]],{n,8}] (* _Harvey P. Dale_, Aug 09 2011 *)

%o (Python)

%o from sympy import isprime

%o def nextsod(n, base):

%o c, b, w = 0, base, 0

%o while True:

%o d = n%b

%o if d+1 < b and c:

%o return (n+1)*b**w + ((c-1)%(b-1)+1)*b**((c-1)//(b-1))-1

%o c += d; n //= b; w += 1

%o def a(n):

%o if n%3 == 0: return 0

%o c, t = 0, 10**(n-1) + ((n-1)%9+1)*10**((n-1)//9)-1

%o while t < 10**n:

%o if isprime(t): c += 1

%o t = nextsod(t, 10)

%o return c

%o print([a(n) for n in range(1, 13)]) # _Michael S. Branicky_, Aug 02 2022

%Y Cf. A069710.

%K base,nonn

%O 1,4

%A _Amarnath Murthy_, Aug 18 2002

%E More terms from _Sascha Kurz_, Aug 23 2002

%E a(4) and a(5) corrected, and example corrected, by _Harvey P. Dale_, Aug 09 2011

%E a(11) corrected and a(13)-a(15) from _Donovan Johnson_, Aug 10 2011

%E a(16)-a(18) from _David Radcliffe_, May 05 2015

%E a(19) from _Michael S. Branicky_, Aug 02 2022

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified July 24 10:37 EDT 2024. Contains 374583 sequences. (Running on oeis4.)