tr(v)=if (v>=0, 1+2*v, -2*v) s = 0 seen(v) = my (w=tr(v)); bittest(s,w) see(v) = my (w=tr(v)); s=bitor(s,2^w) other(p) = { see(p); my (r=p, v); for (x=0, oo, my (d=centerlift(Mod(r, 3))); for (t=-1, +1, if (!seen(v=p + (t-d)*3^x), return (v); ); ); r=(r-d)/3; ); } for (n=0, 6560, print (n " " v=if (n==0, 0, other(v)))) quit