big = 1 000 000 s = 0 S = Set([]) unseen = 1 seen(v) = if (v < big, bit test(s, v), set search(S, v)) see(v) = if (v < big, s = bit or(s, 2^v), S = set union(S, Set([v]))); while (seen(unseen), unseen++) base = 10 other(p) = { see(p); my (mx=floor((base-1)/vecmax(digits(p, base)))); for (i=1, oo, my (v=fromdigits(digits(i,1+mx), base)); if (!seen(v) && sumdigits(p*v, base)==sumdigits(p, base)*sumdigits(v, base), return (v); ); ); } v=1; for (n=1, 10 000, print (n " " v); v=other(v)); quit