login
A342048
Numbers for which the sum of digits equals the product of nonzero digits.
1
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 22, 30, 40, 50, 60, 70, 80, 90, 100, 123, 132, 200, 202, 213, 220, 231, 300, 312, 321, 400, 500, 600, 700, 800, 900, 1000, 1023, 1032, 1124, 1142, 1203, 1214, 1230, 1241, 1302, 1320, 1412, 1421, 2000, 2002, 2013, 2020, 2031, 2103, 2114, 2130, 2141, 2200
OFFSET
1,2
LINKS
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