tr(v)=if (v>=0, 1+2*v, -2*v) s = [] S = [] seen(z)=my (x=tr(real(z)),y=tr(imag(z)));if (x>#s, 0, bittest(s[x],y)) see(z)=my (x=tr(real(z)),y=tr(imag(z)));if (x>#s, s=concat(s,vector(x-#s))); s[x]=bitor(s[x],2^y) allocate mem(2^30) z = vector(2^13-1) { for (n=1, #z, if (n==1, z[n]=0, b=binary(n); d=prod (i=2, #b, if (b[i], 1+I, 1-I)); d/=gcd(real(d),imag(d)); z[n]=z[n\2]; while (seen(z[n]+=d), ); ); see(z[n]); print (n " " imag(z[n])); ); } quit