%I #19 Mar 10 2022 18:33:21
%S 989999,1799999,1889999,1988999,1989899,1989989,1997999,1999799,
%T 1999889,1999979,2699999,2799899,2799989,2879999,2899997,2978999,
%U 2979989,2988899,2989799,2989997,2998997,2999879,2999897,3698999,3789899
%N Primes with digit sum = 53.
%C There are (1, 10, 23, 43, 87, 146, 255, 408, 642) terms below (1, 2, 3, ..., 9)*10^6. Among the 960 terms below 10^7, only {8998991, 8999981, 9899891, 9988991, 9997991, 9999971} end in the digit 1, only 30 end in the digit 3, and 268 end with a digit 7. - _M. F. Hasler_, Mar 09 2022
%H Michael S. Branicky, <a href="/A106782/b106782.txt">Table of n, a(n) for n = 1..10000</a> (terms 1..1000 from Vincenzo Librandi)
%t Select[Prime[Range[270000]],Total[IntegerDigits[#]]==53&] (* _Harvey P. Dale_, Apr 17 2011 *)
%o (Magma) [p: p in PrimesUpTo(3800000) | &+Intseq(p) eq 53]; // _Vincenzo Librandi_, Jul 09 2014
%o (PARI) select( {is_A106782(p)=sumdigits(p)==53&&isprime(p)}, primes([9e5,4e6]\1)) \\ _M. F. Hasler_, Mar 09 2022
%o (Python)
%o from itertools import count, islice
%o from sympy import isprime
%o from sympy.utilities.iterables import multiset_permutations
%o def agen(b=10, sod=53): # generator for any base, sum-of-digits
%o if 0 <= sod < b:
%o yield sod
%o nzdigs = [i for i in range(1, b) if i <= sod]
%o nzmultiset = []
%o for d in range(1, b):
%o nzmultiset += [d]*(sod//d)
%o for d in count(2):
%o fullmultiset = [0]*(d-1-(sod-1)//(b-1)) + nzmultiset
%o for firstdig in nzdigs:
%o target_sum, restmultiset = sod - int(firstdig), fullmultiset[:]
%o restmultiset.remove(firstdig)
%o for p in multiset_permutations(restmultiset, d-1):
%o if sum(p) == target_sum:
%o t = int("".join(map(str, [firstdig]+p)), b)
%o if isprime(t):
%o yield t
%o if p[0] == target_sum:
%o break
%o print(list(islice(agen(), 25))) # _Michael S. Branicky_, Mar 10 2022
%Y Cf. similar sequences listed in A244918.
%K nonn,base
%O 1,1
%A _Zak Seidov_, May 16 2005
|