unseen = 0 pos = 0 \\ mask of terms >= 0 neg = 0 \\ mask of terms <= 0 seen(v) = { if (v >= 0, bittest(pos, +v), bittest(neg, -v)); } see(v) = { if (v >= 0, pos = bitor(pos, 2^+v)); if (v <= 0, neg = bitor(neg, 2^-v)); while (seen(+unseen) && seen(-unseen), unseen++; ); } is = issquare other(p) = { for (v = unseen, oo, if (!seen(+v) && is(abs(p-(+v))), return (+v); ); if (!seen(-v) && is(abs(p-(-v))), return (-v); ); ); } { for (n = 0, 10 000, see(v = if (n==0, 0, other(v))); print (n " " hammingweight(bitxor(pos, neg))); ); } quit