\\ returns k such that n is the k-th zeroless number in base b K(b, n) = { my (d = digits(n, b)); sum(w = 0, #d-1, (b-1)^w) + if (b > 2, fromdigits(apply (t -> t-1, d), b-1), 0); } \\ returns the k-th zeroless number in base c Z(c, k) = { k--; for (w = 1, oo, if (k >= (c-1)^w, k -= (c-1)^w, return (sum (x = 0, w-1, c^x) + if (c > 2, fromdigits(digits(k, c-1), c), 0)); ); ); } F(b, c, n) = { my (d = []); while (n, my (z = valuation(n, b)); d = concat(vector(z), d); n \= b^z; my (nz = 0, t, x = 1); while (t = n % b, n \= b; nz += t * x; x *= b; ); my (k = K(b, nz), z = Z(c, k)); d = concat(digits(z, c), d); ); fromdigits(d, c); } for (n = 0, 2^13, print (n " " F(2, 3, n))) quit