p = 2 q = 3 nxt = [] other(o) = { my (vp = valuation(o, p)); if (#nxt < 1+vp, nxt = concat(nxt, 1); ); my (a=q^vp * nxt[1+vp]); nxt[1+vp]++; if (nxt[1+vp]%q==0, nxt[1+vp]++; ); return (a); } inv = vector(10 000) u = 1 v = 1; for (n=1, oo, v = other(v); if (v<=#inv, inv[v] = n; while (inv[u], print (u " " inv[u]); u++; if (u>#inv, break(2))))); quit