OFFSET
1,2
LINKS
Robert Israel, Table of n, a(n) for n = 1..1000 (first 175 terms from Robert G. Wilson v)
FORMULA
a(3k) = 0 for k > 1.
EXAMPLE
a(68) = 59999999 because 59999999 is the smallest prime with digit sum = 68;
a(100) = 298999999999 because 298999999999 is the smallest prime with digit sum = 100.
MAPLE
g:= proc(s, d) # integers of <=d digits with sum s
if s > 9*d then return [] fi;
if d = 1 then return [s] fi;
[seq(op(map(t -> j*10^(d-1)+ t, g(s-j, d-1))), j=0..9)];
end proc:
f:= proc(n) local d, j, x, y;
if n mod 3 = 0 then return 0 fi;
for d from ceil(n/9) do
if d = 1 then
if isprime(n) and n < 10 then return n
else next
fi
fi;
for j from 1 to 9 do
for y in g(n-j, d-1) do
x:= 10^(d-1)*j + y;
if isprime(x) then return x fi;
od od od;
end proc:
f(1):= 0: f(3):= 3:
map(f, [$1..100]); # Robert Israel, Dec 13 2020
MATHEMATICA
a = Table[0, {100}]; Do[b = Apply[ Plus, IntegerDigits[ Prime[n]]]; If[b < 101 && a[[b]] == 0, a[[b]] = Prime[n]], {n, 1, 10^7} ]; a
f[n_] := If[n > 5 && Mod[n, 3] == 0, 0, Block[{k = 1, lmt, lst = {}, ip = IntegerPartitions[n, Round[1 + n/9], {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}]}, lmt = 1 + Length@ ip; While[k < lmt, AppendTo[lst, Select[ FromDigits@# & /@ Permutations@ ip[[k]], PrimeQ[#] &]]; k++]; Min@ Flatten@ lst]]; f[1] = 0; f[4] = 13; Array[f, 70] (* Robert G. Wilson v, Sep 28 2014 *)
PROG
(PARI) A067180(n)={if(n<2, 0, n<4, n, n%3, my(d=divrem(n, 9)); forprime(p=d[2]*10^d[1]-1, , sumdigits(p)==n&&return(p)))} \\ M. F. Hasler, Nov 04 2018
CROSSREFS
KEYWORD
easy,nonn,base
AUTHOR
Amarnath Murthy, Jan 09 2002
EXTENSIONS
Edited and extended by Robert G. Wilson v, Mar 01 2002
Edited by Ray Chandler, Apr 24 2007
STATUS
approved