mx = 10^14 vv = [0] nb = 0 explore(v) = { if (v#vv, vv = concat(vv, vector(#vv)); ); vv[nb]=v; if (v, explore(10*v); ); explore(100*v+1); explore(1000*v+2); ); } explore(0); vv = Set(vv[2..nb]); n=0; for (k=1, #vv, for (i=1, 1+t=valuation(vv[k], 10), print (n++ " " k); if (n==10 000, break (2)))) quit