login
a(n) is the first member of A106843 with sum of digits n.
1

%I #60 Apr 02 2023 17:49:17

%S 2,3,13,5,6,7,17,9,19,29,39,67,59,69,79,89,99,199,389,489,499,599,699,

%T 997,1889,999,1999,2999,4989,4999,6899,6999,17989,8999,18999,29989,

%U 39989,48999,49999,59999,69999,79999,98999,198999,199999,389999,589989,598999,599999,798999,799999,989999

%N a(n) is the first member of A106843 with sum of digits n.

%C If n is not divisible by 3, a(n) is the least prime with sum of digits n.

%C If n > 3 is divisible by 3 but not by 9, a(n) = 3*p where p is prime.

%C If n is divisible by 9, a(n) is divisible by 9.

%C Conjecture: a(n) == 9 (mod 10) for all n > 25.

%C Conjecture: all terms are zeroless. - _Chai Wah Wu_, Mar 30 2023

%H Chai Wah Wu, <a href="/A361831/b361831.txt">Table of n, a(n) for n = 2..304</a>

%e a(4) = 13 because 13 is the first prime whose sum of digits is 4.

%e a(6) = 6 because 6 = 3*2 where 2 is prime and 6 has sum of digits 6.

%p f106843:= proc(t) local w; w:= padic:-ordp(t,3); isprime(t/3^w) or t/3^w = 1 end proc;

%p V:= Array(2..60): count:= 0:

%p for x from 2 while count < 59 do

%p if f106843(x) then

%p s:= convert(convert(x,base,10),`+`);

%p if s <= 60 and V[s] = 0 then V[s]:= x; count:= count+1; fi

%p fi

%p od:

%p convert(V,list);

%o (Python)

%o from itertools import count

%o from sympy import isprime

%o from sympy.utilities.iterables import multiset_permutations, partitions

%o from gmpy2 import digits

%o def A361831(n):

%o for m in count((n+8)//9):

%o c = (t:=10**m)

%o for a, b in partitions(n,m=m,k=9,size=True):

%o b[0] = (m-a)

%o for s in multiset_permutations(b):

%o if (lambda n:isprime(n) or n==1)(int('0'+digits(k:=int('0'+''.join(str(d) for d in s)),3).rstrip('0'),3)):

%o c = min(c,k)

%o if c < t:

%o return c # _Chai Wah Wu_, Mar 30-31 2023

%Y Cf. A007953, A106843.

%K nonn,base

%O 2,1

%A _Robert Israel_, Mar 26 2023