unseen = 0 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); while (seen(unseen) && seen(-unseen), unseen++) ok(p,v) = abs(p) <= 1 || gcd(p, v)!=1 other(p) = { see(p); for (v = unseen, oo, if (!seen(+v) && ok(p, +v), return (+v); ); if (!seen(-v) && ok(p, -v), return (-v); ); ); } { for (n = 0, 10 000, print (n " " v = if (n==0, 0, other(v))) ); } quit