a(n, base=2) = { my (d=if (n, digits(n, base), [0]), nb=vector(#d)); for (i=1, #d, for (j=0, i-1, my (m=fromdigits(d[j+1..i], base)); nb[i]=if (j==0, [m], setunion(nb[i], Set(apply(p -> p*m, nb[j])))); ); ); #nb[#d]; } for (n=0, 2^14, print (n " " a(n))) quit