OFFSET
1,1
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..10000 (terms 1001..3000 from Vincenzo Librandi and Zak Seidov, terms 1..1000 from Vincenzo Librandi)
FORMULA
MAPLE
a:=proc(n) local nn: nn:=convert(n, base, 10): if isprime(n)=true and add(nn[j], j=1..nops(nn))=10 then n else end if end proc: seq(a(n), n=1..10^4); # Emeric Deutsch, Mar 06 2008
MATHEMATICA
Select[Prime[Range[100000]], Total[IntegerDigits[#]]==10 &] (* Vincenzo Librandi, Jul 08 2014 *)
PROG
(Magma) [p: p in PrimesUpTo(10000) | &+Intseq(p) eq 10]; // Vincenzo Librandi, Jul 08 2014
(PARI) forprime(p=19, 8101, if(10==sumdigits(p), print(p", "))) \\ Zak Seidov, Oct 08 2016
(PARI) (A107579_nxt(p)=until(isprime(p=A228915(p)), ); p); A107579_first(N=100)=vector(N, i, p=if(i>1, A107579_nxt(p), 19)) \\ M. F. Hasler, Mar 15 2022
(Python)
from itertools import count, islice
from sympy import isprime
from sympy.utilities.iterables import multiset_permutations
def agen(b=10, sod=10): # generator for any base, sum-of-digits
if 0 <= sod < b:
yield sod
nzdigs = [i for i in range(1, b) if i <= sod]
nzmultiset = []
for d in range(1, b):
nzmultiset += [d]*(sod//d)
for d in count(2):
fullmultiset = [0]*(d-1-(sod-1)//(b-1)) + nzmultiset
for firstdig in nzdigs:
target_sum, restmultiset = sod - int(firstdig), fullmultiset[:]
restmultiset.remove(firstdig)
for p in multiset_permutations(restmultiset, d-1):
if sum(p) == target_sum:
t = int("".join(map(str, [firstdig]+p)), b)
if isprime(t):
yield t
if p[0] == target_sum:
break
print(list(islice(agen(), 45))) # Michael S. Branicky, Mar 10 2022
(Python)
from sympy import isprime
def A107579(p=19):
"Return a generator of the sequence of all primes >= p with the same digit sum as p."
while True:
if isprime(p): yield p
p = A228915(p) # skip to next larger integer with the same digit sum
a=A107579(); [next(a) for _ in range(50)] # M. F. Hasler, Mar 16 2022
CROSSREFS
KEYWORD
nonn,base,changed
AUTHOR
Zak Seidov, May 16 2005
EXTENSIONS
Edited by N. J. A. Sloane, Feb 20 2009 at the suggestion of Pacha Nambi
STATUS
approved