OFFSET
1,2
LINKS
Robert Israel, Table of n, a(n) for n = 1..10000
EXAMPLE
2103 is in the sequence because 2 + 1 + 0 + 3 = 2 * 1 * 3 = 6.
MAPLE
q:= n-> (l-> is(add(i, i=l)=mul(i, i=l)))(
subs(0=[][], convert(n, base, 10))):
select(q, [$0..3300])[]; # Alois P. Heinz, Feb 26 2021
# alternative
G:= proc(d, dmax, s, p) option remember; local i;
if s + dmax*d < p or s > dmax^d*p then return [] fi;
if d = 0 then return [[]] fi;
[seq(op(map(t -> [i, op(t)], procname(d-1, i, s+i, p*i))), i=1..dmax)]
end proc:
f:= proc(d) local R, k, i;
R:= [seq(op(map(t -> [0$k, op(t)], G(d-k, 9, 0, 1))), k=0..d-1)];
R:= map(op@combinat:-permute, R);
sort(map(t -> add(t[i]*10^(i-1), i=1..d), R))
end proc:
f(4); # Robert Israel, Feb 28 2021
MATHEMATICA
Select[Range[2200], Plus @@ IntegerDigits[#] == Times @@ DeleteCases[IntegerDigits[#], 0] &]
PROG
(Python)
from math import prod
def ok(n):
digs = list(map(int, str(n)))
return sum(digs) == prod([d for d in digs if d != 0])
def aupto(lim): return [m for m in range(1, lim+1) if ok(m)]
print(aupto(2200)) # Michael S. Branicky, Feb 26 2021
(PARI) isok(k) = my(d=select(x->(x>0), digits(k))); vecprod(d) == vecsum(d); \\ Michel Marcus, Feb 26 2021
CROSSREFS
KEYWORD
nonn,base
AUTHOR
Ilya Gutkovskiy, Feb 26 2021
STATUS
approved